zoukankan      html  css  js  c++  java
  • 基于WPF系统框架设计(2)-Fluent Ribbon之HelloWorld

    Fluent/Ribbon是微软在其最新桌面操作系统Windows 7中使用的图形用户界面。 Windows平台的进化,伴随着系统图形界面的重新设计。从Windows XP到Windows Vista,最大的革新就是Windows Aero的引入。在Windows 7 中,Aero被保留下来。 但是,在未来,Windows 7的图形用户界面将朝着Office 2007相同的方向,名称为Fluent/Ribbon。

    Fluent

    现在,我们用WPF作为用户界面开发语言,来做一个简单的实例作为学习的开始。

    • 准备工作:

    需要下载第三方组件为:Fluent.dll,下载网址:http://fluent.codeplex.com/

    • 步骤

    新建项目,选择项目类型:WPF应用程序

    project1

    • 引入Fluent.dll,这里有选择的是支持DotNet 4.0版本(有三个版本,3.5,4.0,4.5)

    project

    • 以XAML模式打开MainWindow.xaml,可以看到WPF应用程序,默认生成的XAML源码:
    <Window x:Class="TLAgent.SecurityManager.WPF.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
            Title="MainWindow" Height="350" Width="525">
        <Grid>
      
        </Grid>
    </Window>
    • 把”Window”标记改为”Fluent:RibbonWindow”,改成如下:
    <Fluent:RibbonWindow x:Class="TLAgent.SecurityManager.WPF.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            xmlns:Fluent="clr-namespace:Fluent;assembly=Fluent"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
         
        </Grid>
    </Fluent:RibbonWindow>

    下一步MainWindow.xaml.cs中修改为:

    using Fluent;
    
    namespace TLAgent.SecurityManager.WPF
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : RibbonWindow//修改为继承RibbonWindow
        {
            public MainWindow()
            {
                InitializeComponent();
            }
        }
    }

    运行后,窗体效果:

    MainWindow

    这个窗体目前有三个主题,实例是Silver主题,还有两个主题:Blue和Black,参考如下:

    Blue:

    Blue

    Black:

    black

    主题配置主要在App.xaml中设置:

    <Application x:Class="TLAgent.SecurityManager.WPF.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="/Fluent;Component/Themes/Generic.xaml" />
                    <ResourceDictionary Source="/Fluent;Component/Themes/Office2010/Black.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Application.Resources>
    </Application>

    但是我们给系统做主题切换一般是通过代码调用接口来实现的,如何设计?

    我给这三个主题样式用Enum设计了这三个主题ThemeStyle: Silver,Blue,Black

    那么怎样让整个系统应用都用这个主题?

    App.xaml.cs中,重写OnStartup方法,把改变主题的方法放在这个方法中执行即可。

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Windows;
    using TLAgent.WPF.Theme;
    
    namespace TLAgent.SecurityManager.WPF
    {
        /// <summary>
        /// Interaction logic for App.xaml
        /// </summary>
        public partial class App : Application
        {
            protected override void OnStartup(StartupEventArgs e)
            {
                ThemeManager.ChangeTheme(ThemeStyle.Silver);
                base.OnStartup(e);
            }
        }
    }

    在系统的任何地方调用这个这个接口都可以改变主题:

    ThemeManager.ChangeTheme(ThemeStyle.Silver);

    实例源码

  • 相关阅读:
    腾讯2014 笔试
    iOS 并发编程之 Operation Queues
    iOS 架构
    loadView and viewDidLoad?
    Referring to weak self inside a nested block
    Weakify和strongify探究
    iOS开发的最佳实践
    iOS 书籍
    Object-C非正式协议与正式协议的区别
    解决element-ui中el-menu组件作为vue-router模式在刷新页面后default-active属性与当前路由页面不一致问题的方法
  • 原文地址:https://www.cnblogs.com/aganqin/p/3269384.html
Copyright © 2011-2022 走看看