RadControls 主题在 Silverlight中的应用 |
RadControls for Silverlight的主题引擎是一个功能非常强大应用程序,对所有RadControls广泛主题的开发,以及一个控件特定的主题。如果主题不包含所需的样式,控件回退到它们的默认风格,所以您可以创建一个只一对的控件,其余部分将展示其默认样式应用主题。 RadControls还提供了标准的控件样式,例如按钮 , 复选框 , 单选按钮等,这使您可以创建具有一致的外观应用样式。
.每个主题是分布式的集合,其中包含一个generic.xaml文件,包含所有的控制风格。最简单的方法适用于一个单一的控件,我们的标准主题之一是设置StyleManager.Theme附加属性:
.每个主题是分布式的集合,其中包含一个generic.xaml文件,包含所有的控制风格。最简单的方法适用于一个单一的控件,我们的标准主题之一是设置StyleManager.Theme附加属性:
[XAML] | |
---|---|
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" ... < telerikNavigation:RadMenu telerik:StyleManager. Theme =””... /> < telerikNavigation:RadTreeView telerik:StyleManager. Theme =””... /> |
请注意,您需要在这种情况下引用Telerik.Windows.Themes.Vista.dll。 |
上述例子长的语法更适合设置自定义主题,而且还为标准的主题:
[XAML] | |
---|---|
<
UserControl.
Resources
> < telerik:Theme x: Key =”” Source =” / Telerik.Windows.Themes.Vista;component / themes / generic.xaml” /> </ UserControl . Resources > < telerikNavigation:RadMenu telerik:StyleManager. Theme =”{StaticResource VistaTheme}”... /> < telerikNavigation:RadTreeView telerik:StyleManager. Theme =”{StaticResource VistaTheme}”... /> |
自定义主题,通常是由一个单一的ResourceDictionary文件,其中包含的控制你要自定义的默认样式。该主题类的源属性应包含该的ResourceDictionary开放 。
例如,如果您的Silverlight应用程序集被命名为MyApplication.dll和自定义主题是放置在MyTheme.xaml,在/主题/ TelerikControls位于/文件夹中的项目, 开放的将是:/MyApplication;component/Themes/TelerikControls/MyTheme.xaml
<
Button
telerik:StyleManager.
Theme
=””
Content
=”me!”
/>
从代码隐藏的主题是略有不同的方式设置:
[C#] | |
---|---|
RadMenu menu =
new
RadMenu();
// Use VistaTheme or Office_BlackTheme, or SummerTheme StyleManager.SetTheme(menu, new VistaTheme()); |
你还可以应用一个自定义主题:
[C#] | |
---|---|
Theme myTheme =
new
Theme(
new
Uri("", UriKind.RelativeOrAbsolute)); StyleManager.SetTheme(menu, myTheme); |
如果你想让所有Telerik使用一个主题,您可以设置应用程序的主题:
[C#] | |
---|---|
StyleManager.ApplicationTheme =
new
VistaTheme();or just new VistaTheme().IsApplicationTheme = true; |
请注意,您需要尽可能的设置好应用程序的主题。最好的地方是page constructor, 或者 Application.Startup event 。 |
[C#] | |
---|---|
public
partial
class
Page : UserControl { public Page() { new VistaTheme().IsApplicationTheme = true; InitializeComponent(); } ... } |
.不幸的是,标准的控件没有用到应用主题,您将需要设置StyleManager.Theme在你的应用环境中 |