The difference of Style on Button and TextBlock,
-
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="FontFamily" Value="Comic Sans MS"/>
<Setter Property="FontSize" Value="20"/><Setter Property="Height" Value="36"/> <Setter Property="Width" Value="60"/> <Button Content="Button" Style="{StaticResource ButtonStyle}"/> <Button Content="Button" Style="{StaticResource ButtonStyle}" Margin="156,144,286,145" />
I am a rookie in WPF, I am wonder why the Button need : Style="{StaticResource ButtonStyle}" , a explicit Style syntax. But the TextBlock don't need it. Thanks
-
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="FontFamily" Value="Comic Sans MS"/>
<Setter Property="FontSize" Value="20"/><Setter Property="Height" Value="36"/> <Setter Property="Width" Value="60"/> <Button Content="Button" Style="{StaticResource ButtonStyle}"/> <Button Content="Button" Style="{StaticResource ButtonStyle}" Margin="156,144,286,145" />
I am a rookie in WPF, I am wonder why the Button need : Style="{StaticResource ButtonStyle}" , a explicit Style syntax. But the TextBlock don't need it. Thanks
I assume you did not write the code for this! Somewhere the author has defined a style called
ButtonStyle
, probably in a resources folder. It will be defined in your App.xaml file as a resources dictionary, or possibly in your window/page .xaml file. The author has decided to customise the standard layout of the Button but not the TextBox.Never underestimate the power of human stupidity RAH
-
I assume you did not write the code for this! Somewhere the author has defined a style called
ButtonStyle
, probably in a resources folder. It will be defined in your App.xaml file as a resources dictionary, or possibly in your window/page .xaml file. The author has decided to customise the standard layout of the Button but not the TextBox.Never underestimate the power of human stupidity RAH
-
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="FontFamily" Value="Comic Sans MS"/>
<Setter Property="FontSize" Value="20"/><Setter Property="Height" Value="36"/> <Setter Property="Width" Value="60"/> <Button Content="Button" Style="{StaticResource ButtonStyle}"/> <Button Content="Button" Style="{StaticResource ButtonStyle}" Margin="156,144,286,145" />
I am a rookie in WPF, I am wonder why the Button need : Style="{StaticResource ButtonStyle}" , a explicit Style syntax. But the TextBlock don't need it. Thanks
In the "Resources" section, you assigned a "Key" ("ButtonStyle" in this case ... it could have been called "Foo") to the Button style; the TextBlock style doesn't have a Key. Any style with a "Key" needs to be referenced via that Key (e.g. StaticResource ButtonStyle) in order to be applied to the relevant control. The TextBlock style (in this case) is applied to any TextBlock that is in the "scope" of that style (without needing a Key).