码迷,mamicode.com
首页 > Windows程序 > 详细

wpf 样式的调用

时间:2017-07-04 18:18:47      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:sch   资源   cti   off   rac   调用   his   black   新建   

这个针对异地调用:


 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;



wpf 样式的调用

标签:sch   资源   cti   off   rac   调用   his   black   新建   

原文地址:http://www.cnblogs.com/mthoutai/p/7117563.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!