这个针对异地调用:
1.在主程序的项目中新建一个Skins的目录。然后再目录里新建一个BlackSkin.xaml的字典资源:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="MenuBackGround" TargetType="Grid">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="#FF282828" Offset="0.434"/>
<GradientStop Color="#9E4B2626" Offset="0.904"/>
<GradientStop Color="#FF412828" Offset="0.268" />
<GradientStop Color="#FF3A3A3A" Offset="0.061" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
假设在另外一个项目中要调用这个样式的话。在前台加上:
<UserControl.Resources>
<ResourceDictionary Source="/Skins/BlackSkin.xaml"></ResourceDictionary>
</UserControl.Resources>
引用这个样式:
<Grid Margin="0" Name="grid2" Grid.Row="1" Style="{StaticResource MenuBackGround}"/>
这样就能够实现样式了。
当然,另一种引用就是在后台写:
grid2.Style=this.FindResource("MenuBackGround") as Style;