当前位置:网站首页>Interface component telerik UI for WPF Getting Started Guide - how to switch custom styles using themes
Interface component telerik UI for WPF Getting Started Guide - how to switch custom styles using themes
2022-06-28 01:21:00 【Interface development Starling】
obtain Telerik UI for WPF The official latest edition
Theme with implicit styles , You can choose to change the theme of the control at run time , Without having to recreate UI.
The resources in the merge dictionary occupy a position in the resource lock range , This location is just after the scope of the main resource dictionary into which they are merged . What you can do is isolate the custom styles in a separate resource dictionary , And add them to the default dictionary every time you change topics .
for example , You can follow the steps below :
1. Create a new application and start at Telerik UI for WPF In the installation folder Binaries.NoXaml Add the required assemblies and theme assemblies to the folder :
- Telerik.Windows.Controls.dll
- Telerik.Windows.Controls.Input.dll
- Telerik.Windows.Themes.Office_Black.dll
- Telerik.Windows.Themes.Office2016.dll
2. stay App.xaml Add the corresponding resource dictionary for the default topic in :
Example 1: Merge resource dictionaries
XAML
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
<!-- ... -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>Be careful : first , We merged Office_Black Resource dictionary for topic .
3. Add some of the controls you select to the layout root directory of the application , There are also two buttons for switching between topics .
Example 2: Add buttons to switch between topics
XAML
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<telerik:RadButton Content="Button" VerticalAlignment="Center" Width="100"/>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button x:Name="Office_Black" Margin="5" Content="Office__Black" Click="Office_Black_Click"/>
<Button x:Name="Office2016" Margin="5" Content="Office2016" Click="Office2016_Click"/>
</StackPanel>
</Grid>4. Now? , Add a custom style to the project Themes Folder name CustomStyles_Office_Black.xaml and CustomStyles_Office2016.xaml Separate resource dictionaries for different topics , These custom resource dictionaries will have the following :
Example 3: Add custom styles to a separate resource dictionary
XAML
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="telerik:RadButton" BasedOn="{StaticResource RadButtonStyle}">
<Setter Property="Background" Value="Black"/>
<Setter Property="Foreground" Value="White"/>
</Style>
</ResourceDictionary>Be careful : Creating separate resource dictionaries for different topics allows easy customization on a per topic basis , But you can use a single dictionary when switching topics and merge only this dictionary , If you don't have any theme specific changes . Such changes will include any modified space templates , Because these templates vary by topic , And it may cause errors during switching .
Example 4: Add dictionary to MergedDictionaries
XAML
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml"/>
<ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.Input.xaml"/>
<!-- ... -->
<ResourceDictionary Source="/ProjectName;component/Themes/CustomStyles_Office_Black.xaml"/>
</ResourceDictionary.MergedDictionaries>Please note that , You should ProjectName Replace with the actual name of the project .
6. then , At the button Click In process , We will clear the merged dictionary from the application resource , And merge the new resource dictionary in the topic assembly with the custom styles contained in the custom resource dictionary :
Example 5: Clear and merge dictionaries when the button is clicked
C#
private void Office_Black_Click(object sender, RoutedEventArgs e)
{
this.MergeDictionaries("Office_Black");
}
private void Office2016_Click(object sender, RoutedEventArgs e)
{
this.MergeDictionaries("Office2016");
}
private void MergeDictionaries(string theme)
{
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
{
Source = new Uri("/Telerik.Windows.Themes." + theme + ";component/Themes/System.Windows.xaml", UriKind.RelativeOrAbsolute)
});
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
{
Source = new Uri("/Telerik.Windows.Themes." + theme + ";component/Themes/Telerik.Windows.Controls.xaml", UriKind.RelativeOrAbsolute)
});
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
{
Source = new Uri("/Telerik.Windows.Themes." + theme + ";component/Themes/Telerik.Windows.Controls.Input.xaml", UriKind.RelativeOrAbsolute)
});
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
{
Source = new Uri("/ProjectName;component/Themes/CustomStyles_" + theme + ".xaml", UriKind.RelativeOrAbsolute)
});
}Please note that ,MergeDictionaries The topic provided in should match the name of the corresponding topic assembly , for example - Expression_Dark、Office2016Touch、Material. Using this method , You can switch to Telerik UI for WPF Any theme provided by the suite .
The result based on the above code is shown in Figure 1 Shown .
chart 1: with Office_Black and Office 2016 Topic radio buttons

Telerik UI for WPF | Download trial
Telerik UI for WPF Have more than 100 Control to create beautiful 、 High performance desktop applications , At the same time, it can quickly build enterprise office WPF Applications .UI for WPF Support MVVM、 Touch, etc , The application created is reliable and well structured , Very easy to maintain , Its intuitive API Will integrate seamlessly Visual Studio Toolbox .
Telerik_KendoUI Product technology exchange group :726377843 Welcome to group discussion
Stay up to date Kendo UI The latest news , Please pay attention to Telerik Chinese net !
边栏推荐
- 吸顶方案1
- How to build an e-commerce platform at low cost
- 1696D. Permutation graph thinking
- Modern programming languages: zig
- 信息学奥赛一本通 1359:围成面积
- Efficient supplier management in supply chain
- Distortion model of SDF learning
- 投资场内ETF基金是靠谱吗,场内ETF基金安全吗
- 攻击队攻击方式复盘总结
- Squid proxy server (Web cache layer for cache acceleration)
猜你喜欢

深入解析kubernetes controller-runtime

Redis主从复制、哨兵模式、集群的概述与搭建

Deploy a mongodb single node server locally, enable auth authentication and enable oplog

Proe/Creo产品结构设计-钻研不断

SQL Server 2016 detailed installation tutorial (with registration code and resources)

LabVIEW continuous sampling and limited sampling mode

Overview and construction of redis master-slave replication, sentinel mode and cluster

Leetcode 720. The longest word in the dictionary

Summary of wuenda's machine learning course (14)_ Dimensionality reduction

LabVIEW连续采样与有限采样模式
随机推荐
攻击队攻击方式复盘总结
联想拯救者R720如何组建双通道内存
Matlb| optimal configuration of microgrid in distribution system based on complex network
awk注意的几个问题
现在炒股网上开户安全吗?新手刚上路,求答案
什么是过孔式导电滑环?
What are the requirements for customizing the slip ring for UAV
AI+临床试验患者招募|Massive Bio完成900万美元A轮融资
Alchemy (3): how to do a good job in interfacing a business process
MySQL 18: execution of write statements
.mp4视频测试地址
Is it safe to open a stock account online now? Select a listed securities firm, and the fastest time to open an account is 8 minutes
最新MySQL高级SQL语句大全
每次启动项目的服务,电脑竟然乖乖的帮我打开了浏览器,100行源码揭秘!
Sword finger offer 65 Add without adding, subtracting, multiplying, dividing
#795 Div.2 D. Max GEQ Sum 单调栈
Taro--- day1--- construction project
Acwing第 57 场周赛【未完结】
Which securities company is better and safer to open an account for stock speculation
为什么要选择不锈钢旋转接头