随笔 - 27  文章 - 0  评论 - 316  阅读 - 15万 

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);

实例源码

posted on   aganqin  阅读(9494)  评论(17编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示