XAML 样式 与 CSS
<ResourceDictiontory Source="css/stlye.xaml"></ResourceDictiontory>
等同于
<link rel="stylesheet" href="css/style.css" />
代码加载xaml style
ResourceDictionary resources = null;
using (FileStream fs = new FileStream(文件路径+@"style.xaml", FileMode.Open, FileAccess.Read))
{
resources = (ResourceDictionary)XamlReader.Load(fs);
}
Application.Current.Resources = resources;
===============================================
<Style TagetType="Button">
<Setter Property="Background" value="Red"></Setter>
......
</Style>
等同于
input[type="button"]{
background:red;
......
}
===============================================
<Style TagetType="Button" x:Key="btn1">
<Setter Property="Background" value="Red"></Setter>
......
</Style>
应用:
<Button Content="Button" Style="{StaticResource btn1}"/>
等同于
.btn1{
background:red;
......
}
应用:
<input type="button" class="btn1" />