WPF DevExpress 更换主题

来源:互联网 发布:男子遭遇网络诈骗 编辑:程序博客网 时间:2024/06/05 06:25

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

最后,贴一张效果图:



0 0
原创粉丝点击