天天看點

Silverlight Telerik控件學習:主題Theme切換

telerik的RadControls for Silverlight内置了以下幾種主題樣式:

Office Black - 這是預設值,無需加載其它任何dll檔案. 

Office Blue - 需要引用 Telerik.Windows.Themes.Office_Blue.dll.

Office Silver - 需要引用 Telerik.Windows.Themes.Office_Silver.dll.

Summer - 需要引用 Telerik.Windows.Themes.Summer.dll.

Vista - 需要引用 Telerik.Windows.Themes.Vista.dll.

Windows 7 - 需要引用 Telerik.Windows.Themes.Windows7.dll.

Transparent - 需要引用 Telerik.Windows.Themes.Transparent.dll

下面是切換方法:

1、局部切換/設定法

 <telerik:RadButton Height="20" Width="80" Content="彈出" telerik:StyleManager.Theme="Windows7"  Click="RadButton_Click" />

這個好比css中的内聯樣式,僅影響目前控件

2、全局切換/設定法

在App.xaml.cs檔案中App的構造函數裡加一行代碼,參考下面:

        public App()

        {

            StyleManager.ApplicationTheme = new Windows7Theme();

            this.Startup += this.Application_Startup;

            this.Exit += this.Application_Exit;

            this.UnhandledException += this.Application_UnhandledException;

            InitializeComponent();

        }

這個好比網頁制作中用link ref引用的css全局檔案

3、自定義主題

如果内置的主題你都覺得不滿意,還可以自定義,方法如下:

先定義一個主題類

public class CustomTheme : Telerik.Windows.Controls.Theme

{

}

然後在這個類的構造函數裡指明Source

public CustomTheme()

   this.Source = new Uri( "/Telerik.Windows.Themes.CustomTheme;component/themes/Generic.xaml", UriKind.Relative );

後面的事情,就跟前面提到的1,2中完全一樣了

作者:菩提樹下的楊過