Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 本地值与样式_C#_Wpf_Xaml_Styling - Fatal编程技术网

C# 本地值与样式

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

哪种方法更适合设置窗口样式:

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" 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:我不会推荐链接页面,那里有很多不好的内容,我会参考。。。