WPF统一设置Style的问题
我想让一个StackPanel里面的所有控件(不管是什么类型)都有一样的宽度和高度,我写成
<StackPanel.Resources>
<Style TargetType="{x:Type FrameworkElement}">
<Setter Property="Width" Value="60" />
<Setter Property="Height" Value="50" />
</Style>
</StackPanel.Resources>
<Grid>
<Grid.Resources>
<Style x:Key="test1" TargetType="{x:Type FrameworkElement}">
<Setter Property="Height" Value="30"/>
<Setter Property="Width" Value=" 100"/>
</Style>
</Grid.Resources>
<TextBox HorizontalAlignment="Left" Margin="92,174,0,0" Name="textBox1" VerticalAlignment="Top"
Style="{StaticResource ResourceKey=test1}" />
<Button Content="Button" HorizontalAlignment="Left" Margin="292,172,0,0" Name="button1" VerticalAlignment="Top"
Style="{StaticResource ResourceKey=test1}" />
</Grid>
<Grid>
<StackPanel>
<StackPanel.Resources>
<Style x:Key="SDFSDSF" TargetType ="{x:Type FrameworkElement}">
<Setter Property ="Height" Value="200"/>
<Setter Property ="Width" Value="20"/>
</Style>
</StackPanel.Resources>
<Button Style="{StaticResource SDFSDSF}">
SDFSDF
</Button>
</StackPanel>
</Grid>
Style FrameworkElementStyleTest = this.Resources["FrameworkElementStyle"] as Style;
Button a = new Button();
a.Style = FrameworkElementStyleTest;