WPF DevExpress 更换主题

wpf中更换主题包含多种方式,这里介绍两种常用方式,方式一:在xaml中更换主题即使用默认主题,方式二:在软件页面中更换主题。

方式一实现方法:

在窗体属性中添加主题属性即可:dx:ThemeManager.ThemeName="Office2007Blue"

方式二实现方式:

方式二实现想比较方式一复杂一点,这里我列举一种相对简单的方法:

第一步:添加主题图片,可以从源码中查找。

第二步:在RibbonGalleryBarItem中添加主题列表(也可以使用其他控件),xaml代码如下:

<dxr:RibbonGalleryBarItem x: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="48,48" ItemClick="Gallery_ItemClick" ItemGlyphSize="24,24" ItemGlyphStretch="Uniform">
                            <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:GalleryItem Caption="Office 2013 DarkGray" Glyph="Images/ThemeIcons/Office2013DarkGray_48x48.png"/>
                                <dxb:GalleryItem Caption="Office 2013 LightGray" Glyph="Images/ThemeIcons/Office2013LightGray_48x48.png"/>
                            </dxb:GalleryItemGroup>
                        </dxb:Gallery>
                    </dxr:RibbonGalleryBarItem.Gallery>
                </dxr:RibbonGalleryBarItem>
关联子项,代码如下:

<dxr:RibbonDefaultPageCategory>
                            <dxr:RibbonPageGroup Caption="主题">
                                <dxr:RibbonGalleryBarItemLink BarItemName="gTheme"/>
                            </dxr:RibbonPageGroup>
                        </dxr:RibbonPage>
                    </dxr:RibbonDefaultPageCategory>

第三步,在 Gallery_ItemClick事件中添加切换主题的代码如下所示:

        private void Gallery_ItemClick(object sender, DevExpress.Xpf.Bars.GalleryItemEventArgs e)
        {
            string themeName = (string)e.Item.Caption;
            themeName = themeName.Replace(" ", string.Empty);
            DevExpress.Xpf.Core.ThemeManager.SetThemeName(this, themeName);
        }

最后,贴一张效果图:



  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值