码迷,mamicode.com
首页 > 其他好文 > 详细

c#代码使用ResourceDictionary样式

时间:2014-07-02 18:05:48      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   使用   width   

对于ResourceDictionary样式代码:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
...
 <Style x:Key="AlertButton" TargetType="ButtonBase" BasedOn="{StaticResource SystemButtonBase}">
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Margin" Value="8"/>
        <Setter Property="Padding" Value="4"/>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Cursor" Value="Hand"></Setter>
                <Setter Property="Opacity" Value=".8" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Opacity" Value=".4" />
            </Trigger>
        </Style.Triggers>
    </Style>
...
</ResourceDictionary>

使用C#代码引用:

            ResourceDictionary mystyles;
            mystyles = new ResourceDictionary();
            mystyles.Source = new Uri("/FirstFloor.ModernUI;component/Assets/Button.xaml",
                    UriKind.RelativeOrAbsolute);
            System.Windows.Style btnStyle = mystyles["AlertButton"] as Style;

        new Button
                {
                    Foreground = new SolidColorBrush(Colors.White),
                    Content = content,
                    Command = this.CloseCommand,
                    CommandParameter = result,
                    IsDefault = false,
                    IsCancel = isCancel,
                    MinHeight = 21,
                    MinWidth = 65,
                    Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(252, 73, 0)),
                    Margin = new Thickness(4, 0, 4, 0)
                        ,
                    Style = new Style(typeof(Button), btnStyle) { Triggers = { tRed } }
                };

 

 

 

 

c#代码使用ResourceDictionary样式,布布扣,bubuko.com

c#代码使用ResourceDictionary样式

标签:style   blog   http   color   使用   width   

原文地址:http://www.cnblogs.com/9527y/p/3819862.html

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