C# 本地值与样式
哪种方法更适合设置窗口样式: 1。元素中的属性如下:C# 本地值与样式,c#,wpf,xaml,styling,C#,Wpf,Xaml,Styling,哪种方法更适合设置窗口样式: 1。元素中的属性如下: <StackPanel Width="888" Height="491" Name="LoginBox" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="-100,0,0,0"> 2。位于资源字典中的样式如下: <StackPanel Width="888" Height="491" Name="LoginBox" HorizontalAl
<StackPanel Width="888" Height="491" Name="LoginBox" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="-100,0,0,0">
2。位于资源字典中的样式如下:
<StackPanel Width="888" Height="491" Name="LoginBox" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="-100,0,0,0">
窗口:
<StackPanel Name="LoginBox" Style="{StaticResource LoginBox}">
字典:
<Style x:Key="LoginBox" TargetType="StackPanel">
<Setter Property="Width" Value="888" />
<Setter Property="Height" Value="491" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="-100,0,0,0" />
</Style>
哪种方法运行得更快,哪种方法更容易编辑,等等
谢谢。样式是对属性进行分组的一种很好的方式,当您要对多个控件使用相同的属性设置时,应该使用样式。例如,如果应用程序中的所有标签使用相同的字体族和字体权重,则应考虑使用样式。通过这种方式,您可以轻松编辑应用程序的整个外观。共享相同设置的控件越多,就越有理由使用样式 我通常声明样式尽可能接近将要使用的位置。应用程序范围的样式进入资源字典,单个控件中使用的样式在该控件中声明 利用样式继承创建子样式以进一步简化编辑
有关良好的教程和说明,请参见 @ItehnologicalDisexisting:我不会推荐链接页面,那里有很多不好的内容,我会参考。。。