我定义了一个自定义的WPF样式。我想要网格中的任何按钮都是红色的。但如果我定义这种风格,整个网格是红色!为什么?我明确定义了Button.Background。为什么WPF样式应用于父控件?
<Window x:Class="WpfApplication2.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">
<Window.Resources>
<Style x:Key="MyStyle">
<Setter Property="Button.Background" Value="Red" /> <!-- Only inner buttons -->
</Style>
</Window.Resources>
<Grid Style="{StaticResource MyStyle}">
<Button Content="Go" Margin="29,36,385,239" />
</Grid>
</Window>
不,因为样式必须应用于网格。并应包含不同内部控件的所有不同样式 – Robert 2011-02-10 13:16:07