最近在看wpf相关东西,虽然有过两年的wpf方面的开发经验,但是当时开发的时候,许多东西一知半解,至今都是模模糊糊,框架基本是别人搭建,自己也就照着模板写写,现在许多东西慢慢的理解了,回顾以前的若干记忆,然后解决自己不懂的方面,在CSDN做记录,写下一些自己的理解,方便以后查阅:

    今天写的是关于wpf的资源字典里面做触发器,然后主界面进行调用:

   1: 首先建立了个wpf窗体程序WpfApplication1;工程里面自动生成App.xaml和MainWindow.xaml两个文件,这两个文件就不做介绍了,App.xaml会在下面用到。

    2:然后呢。一般都会将控件的触发器写成这样:

  <Button Name="btnUpdate" Grid.Row="1" Width="100" Height="30" Content="更 新"  Command="{Binding CmdCommand}" CommandParameter="{Binding Oberve}">
                <Button.Style>
                    <Style TargetType="{x:Type Button}">
                        <Style.Triggers>
                            <Trigger Property="Button.IsMouseOver" Value="True">
                                <Setter Property="Button.Foreground" Value="Blue"/>
                            </Trigger>
                            <Trigger Property="Button.IsPressed" Value="True">
                                <Setter Property="Button.Foreground" Value="Red"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
        </Button>

  那么控件多的时候,就显得臃肿了,于是就想到了【资源字典】,在资源字典里面写这些,然后调用,新建了【Dictionary1.xaml】文件

将要是实现的式样写进它里面:

  <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="CircleButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Border.BorderThickness" Value="1,1,1,1" />
        <Setter Property="Border.CornerRadius" Value="3" />
        <Setter Property="Height" Value="36" />
        <Setter Property="Width" Value="36" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid>
                        <Ellipse Fill="{TemplateBinding Background}"/>
                        <Ellipse>
                            <Ellipse.Fill>
                                <RadialGradientBrush>
                                    <GradientStop Offset="0" Color="#00000000"/>
                                    <GradientStop Offset="0.88" Color="#00000000"/>
                                    <GradientStop Offset="1" Color="#80000000"/>
                                </RadialGradientBrush>
                            </Ellipse.Fill>
                        </Ellipse>
                        <Ellipse Margin="10" x:Name="highlightCircle" >
                            <Ellipse.Fill >
                                <LinearGradientBrush >
                                    <GradientStop Offset="0" Color="#50FFFFFF"/>
                                    <GradientStop Offset="0.5" Color="#00FFFFFF"/>
                                    <GradientStop Offset="1" Color="#50FFFFFF"/>
                                </LinearGradientBrush>
                            </Ellipse.Fill>
                        </Ellipse>
                        <ContentPresenter x:Name="content" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="RenderTransform">
                        <Setter.Value>
                            <RotateTransform Angle="10"></RotateTransform>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="RenderTransformOrigin" Value="0.5,0.5"></Setter>
                    <Setter Property="Background" Value="#FF0CC030" />
                </Trigger>
                <Trigger Property="IsPressed" Value="True">
                    <Setter Property="Foreground" Value="Red"/>
                </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>

     3:这下就用到App.xaml发挥作用了;App这个文件是协助运行主窗口的文件,在app文件里面将数据资源里面的东东引进:

   <Application x:Class="WpfApplication1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Dictionary1.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

  4:这样后,MainWindow.xaml文件中就可以引进数据字典里面的式样和触发器了;

        <Grid>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="157,119,0,0" Name="button1"
  Style="{StaticResource CircleButtonStyle}"//引进数据字典里面的式样
                VerticalAlignment="Top" Width="75" />
    </Grid>

生成如下效果:

WPF之资源字典zz的更多相关文章

  1. WPF 为资源字典 添加事件响应的后台类

    原文:WPF 为资源字典 添加事件响应的后台类 前言,有许多同学在写WPF程序时在资源字典里加入了其它控件,但又想写事件来控制这个控件,但是资源字典没有CS文件,不像窗体XAML还有一个后台的CS文件 ...

  2. WPF合并资源字典

    1.合并多个外部资源字典成为本地字典 示例代码 <Page.Resources> <ResourceDictionary> <ResourceDictionary.Mer ...

  3. WPF使用资源字典组织资源

    转载:http://blog.163.com/wangzhenguo2005@126/blog/static/371405262010111413321728/     首先在解决方案资源管理器中添加 ...

  4. wpf 切换资源字典的2中方式

    var _1200RDUri = new Uri(String.Format(@"/aa;Component/Themes/1200Theme.xaml"), UriKind.Re ...

  5. WPF 遍历资源字典中的控件

    object obItem=this.FindResource("canvasdt"); if (obItem is System.Windows.DataTemplate) { ...

  6. [WPF]资源字典——程序集之间的资源共享 简单换皮肤

    直接上代码,已便已后自己查况阅,新手也可以看! 1.新建一个资料类和一个WPF工程 2.APP.XAML应该资源字典,注意应Source格式,前面一定要有“/” <ResourceDiction ...

  7. WPF 资源字典

    使用好处:存储需要被本地话的内容(错误消息字符串等,实现软编码),减少重复的代码,重用样式,实现多个项目之间的共享资源;修改一个地方所有引用的地方都会被修改,方便统一风格; 使用方法,归纳起来主要有下 ...

  8. wpf多程序集之间共享资源字典--CLR名称空间未定义云云

    wpf多程序集之间共享资源字典--CLR名称空间未定义云云 分类: WPF 2012-10-28 10:57 1162人阅读 评论(0) 收藏 举报 以下介绍如何创建可用于在多个程序集之间共享的资源字 ...

  9. (转载)资源字典(Pro WPF 学习)

    原地址:http://www.cnblogs.com/yxhq/archive/2012/07/09/2582508.html 1.创建资源字典 下面是一个资源字典(AppBrushes.xaml), ...

随机推荐

  1. [Effective JavaScript 笔记]第28条:不要信赖函数对象的toString方法

    js函数有一个非凡的特性,即将其源代码重现为字符串的能力. (function(x){ return x+1 }).toString();//"function (x){ return x+ ...

  2. HDOJ 1102 生成树

    Constructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. JTA集成JOTM或Atomikos配置分布式事务(Tomcat应用服务器)

    一.以下介绍Spring中直接集成JOTM提供JTA事务管理.将JOTM集成到Tomcat中. (经过测试JOTM在批量持久化时有BUG需要修改源码GenericPool类解决)! 参考文章http: ...

  4. Shortest Word Distance

    Given a list of words and two words word1 and word2, return the shortest distance between these two ...

  5. JS 保留小数点后面2位小数

    1. 最笨的办法....... [我就怎么干的.........] function get(){    var s = 22.127456 + "";    var str = ...

  6. Selenium测试Ajax程序(转)

    上周末参加了Qclub的百度技术沙龙,听了百度的孙景卫讲了Web自动化测试,讲的非常好,然后在小组讨论时又有幸座在了一起.我们讨论的一个内容,就是Ajax应用程序比原来的非Ajax程序更不易测试,这里 ...

  7. ARGB32 to YUV12 利用 SDL1.2 SDL_ttf 在视频表面输出文本

    提示:ARGB alpha通道的A + 原YUV表面的y0 + 要写进去的y1 = 计算出新的y2. 计算公式为 ( y1 * a + y0 * ( 255 - a ) ) / 255 void rg ...

  8. Java for LeetCode 070 Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  9. 【JAVA、C++】LeetCode 009 Palindrome Number

    Determine whether an integer is a palindrome. Do this without extra space. 解题思路一: 双指针法,逐位判断 Java代码如下 ...

  10. July 17th, Week 30th Sunday, 2016

    You are beautiful, but that is not why I love you. 你如此美丽,但我并非因此而爱你. Although we have always been tol ...