WPF的DEV换肤 连WPF自带控件一起换肤

本文介绍了一种在WPF应用程序中实现界面换肤的方法。通过使用DevExpress控件和自定义代码,作者展示了如何轻松地为应用程序添加不同的主题风格。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     小弟最近采用WPF,想简便的换肤,所以研究了一下!好了,废话不多说。先上图,上面ribbon是DEV控件 下面乱乱的全是WPF自带控件哦。


     源码地址:http://download.youkuaiyun.com/detail/wangtao510/8127887 


     换肤步骤如下:

    1、两个DLL ,DevExpress.DemoData.v13.1.Core.dll   ,DevExpress.Xpf.DemoBase.v13.1.dll可以去dev安装路径下找;

    2、DemoModuleControl.cs类 添加进系统,源码已上传 下面提供源码地址

    3、首先建立一个窗体MainWindow  更改窗体信息 

    4;这里也要改

    5、新建dev的ribbonWindow窗体DXRibbonWindow 然后再Grid下添加如下代码 

<dxb:BarManager>
<dxb:BarManager.Items>
                <dxr:RibbonGalleryBarItem Name="gTheme"  >
                    <dxr:RibbonGalleryBarItem.Gallery>
                        <dxb:Gallery MinColCount="2" ColCount="10" RowCount="2" ItemCheckMode="Single" AllowHoverAnimation="True" AllowHoverImages="True" FilterCaption="Themes" IsItemCaptionVisible="False" ItemCaptionHorizontalAlignment="Center" HoverGlyphSize="96,96" ItemClick="Gallery_ItemClick">
                            <dxb:Gallery.Groups>
                                <dxb:GalleryItemGroup Caption="Standard">
                                    <dxb:GalleryItem Caption="DXStyle" Glyph="Images/ThemeIcons/DXStyle.png"/>
                                    <dxb:GalleryItem Caption="VS2010" Glyph="Images/ThemeIcons/VS2010.png"/>
                                    <dxb:GalleryItem Caption="MetropolisDark" Glyph="Images/ThemeIcons/MetropolisDark.png"/>
                                    <dxb:GalleryItem Caption="MetropolisLight" Glyph="Images/ThemeIcons/MetropolisLight.png"/>
                                    <dxb:GalleryItem Caption="Seven" Glyph="Images/ThemeIcons/Seven_48x48.png"/>
                                    <dxb:GalleryItem Caption="Light Gray" Glyph="Images/ThemeIcons/LightGray_48x48.png" />
                                    <dxb:GalleryItem Caption="Deep Blue" Glyph="Images/ThemeIcons/DeepBlue_48x48.png"/>
                                </dxb:GalleryItemGroup>
                                <dxb:GalleryItemGroup Caption="Office2007">
                                    <dxb:GalleryItem Caption="Office 2007 Black" Glyph="Images/ThemeIcons/Office2007Black_48x48.png"/>
                                    <dxb:GalleryItem Caption="Office 2007 Blue" Glyph="Images/ThemeIcons/Office2007Blue_48x48.png"/>
                                    <dxb:GalleryItem Caption="Office 2007 Silver" Glyph="Images/ThemeIcons/Office2007Silver_48x48.png"/>
                                </dxb:GalleryItemGroup>
                                <dxb:GalleryItemGroup Caption="Office2010">
                                    <dxb:GalleryItem Caption="Office 2010 Black" Glyph="Images/ThemeIcons/Office2010Black_48x48.png"/>
                                    <dxb:GalleryItem Caption="Office 2010 Blue" Glyph="Images/ThemeIcons/Office2010Blue_48x48.png"/>
                                    <dxb:GalleryItem Caption="Office 2010 Silver" Glyph="Images/ThemeIcons/Office2010Silver_48x48.png"/>
                                </dxb:GalleryItemGroup>
                                <dxb:GalleryItemGroup Caption="Office2013">
                                    <dxb:GalleryItem Caption="Office 2013" Glyph="Images/ThemeIcons/Office2013_48x48.png"/>
                                </dxb:GalleryItemGroup>
                            </dxb:Gallery.Groups>
                        </dxb:Gallery>
                    </dxr:RibbonGalleryBarItem.Gallery>
                </dxr:RibbonGalleryBarItem>
            </dxb:BarManager.Items>
</dxb:BarManager>

 6、在ribbonPageGroup中添加的代码 

 7、在DXRibbonWindow的cs代码页面添加代码

               void DXRibbonWindow1_Loaded(object sender, RoutedEventArgs e)

        {
            MainWindow a = new MainWindow();
            OwnerDemoModule = a;
        }
        public RibbonDemoModule OwnerDemoModule { get; set; }
        private void Gallery_ItemClick(object sender, GalleryItemEventArgs e)
        {
            string themeName = (string)e.Item.Caption;
            themeName = themeName.Replace(" ", string.Empty);
            OwnerDemoModule.Theme = Theme.FindTheme(themeName);
        }

添加相应引用 生成就可以了!


源码网址:http://download.youkuaiyun.com/detail/wangtao510/8127887 

如果没有积分就直接问我要把!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值