• [转]使WPF程序应用预置的控件风格, 如Aero, Luna, Royale, Classic等


    WPF预设有Aero, Classic, Luna, Royale主题, WPF程序会根据Windows主题决定WPF程序所使用的控件风格, 而且当Windows主题不是Aero, Luna或Royale, 而是其他主题的话, WPF将会采用比较丑的Classic主题, 那我怎么让WPF程序使用指定的主题呢?

    其实很简单, 下面实例如何设定为Aero主题:
    在WPF项目中添加PresentationFramework.Aero.dll这个引用, 然后在程序的Resources中加入
        <Application.Resources>
            
    <ResourceDictionary Source="/PresentationFramework.Aero, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/aero.normalcolor.xaml" />
        
    </Application.Resources>
    这相当于把PresentationFramework.Aero程序集中的空间风格代码引用到当前程序中.
    注意, 项目必须引用主题对应的Assembly, 比如PresentationFramework.Aero.dll, PresentationFramework.Royale.dll等等, 它们可以在"Program Files\Reference Assemblies\Microsoft\Framework\v3.0" 或者 GAC中找到.
    上面的XAML代码也可以使用相应的C#代码代替, 比如在Application的Startup事件处理函数中加入代码:
        protected override void OnStartup(StartupEventArgs e)
        {
            
    base.OnStartup(e);
            Uri aero 
    = new Uri("/PresentationFramework.Aero, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/aero.normalcolor.xaml", UriKind.Relative);
            Resources.MergedDictionaries.Add(Application.LoadComponent(aero) 
    as ResourceDictionary); 
        }
    当然也可以在Window的Resources中加入这个ResourceDictionary, 那样就只会在这个Window中采用此主题.

    要指定其他主题的方法也差不多, 也就是引用相关dll和添加Resources.
    WPF中的Aero主题和Windows Vista里的Aero主题控件风格完全一样, 包括譬如MouseEnter时的动画效果, 下面是在启用了Luna Element 4 视觉效果的Windows 2003系统运行的使用了Aero主题的WPF程序截图:



    但WPF里的Aero主题在非Windows Vista系统是没有玻璃效果的.. 那不是GDI就能做到的东西..
  • 相关阅读:
    【FastJSON】使用JSON.toJSONString()-解决FastJson中“$ref 循环引用”的问题
    格林威治时间(GTM)转北京时间
    @RenderBody、@RenderSection、@RenderPage、Html.RenderPartial、Html.RenderAction的作用和区别
    Net操作Excel(终极方法NPOI)
    10款.net 图形插件
    23种设计模式
    asp.net页面关闭的时候如何触发事件?
    IIS HTTP 错误 404.17
    Win10 Sql2008R2 在关闭【0x80041033】
    国内外前端(js)开发框架对比
  • 原文地址:https://www.cnblogs.com/chenlhuaf/p/1133100.html
Copyright © 2020-2023  润新知