gpt4 book ai didi

c# - 为什么只有一些子元素的属性由其父元素定义

转载 作者:行者123 更新时间:2023-11-30 13:05:53 37 4
gpt4 key购买 nike

<Window x:Class="tests.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Background="Red" Foreground="Cyan">
<StackPanel VerticalAlignment="Center">
<Button>123</Button>
<TextBlock>123</TextBlock>
<TextBox>123</TextBox>
</StackPanel>
</Window>

在上面的代码中,只有 TextBlock 会“继承”前景色和背景色。 Button 和 TextBox 不应该也有那些颜色吗?为什么他们没有呢? alt text http://img707.imageshack.us/img707/8014/5uslgmbzkbyurgwuwgqtzv2.png

最佳答案

这是因为 Button 特地选择退出 Background 值继承,以便具有一致的外观。参见 en.csharp-online.net/WPF_Concepts—Property_Value_Inheritance了解更多详情。

关于c# - 为什么只有一些子元素的属性由其父元素定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2305593/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com