天天看點

Silverlight中資源檔案的引用

<a href="http://blog.csdn.net/taomanman/article/details/6777291"></a>

<a href="http://blog.csdn.net/taomanman/article/details/6777291">http://blog.csdn.net/taomanman/article/details/6777291</a>

1、建立一個資源檔案,比如: Gaugestyle.xaml和MenuButton.xaml

2、在App.xaml中添加該資源:

&lt;Application  

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  

    x:Class="spjl1.App"&gt;  

    &lt;Application.Resources&gt;  

        &lt;!-- Resources scoped at the Application level should be defined here. --&gt;  

        &lt;ResourceDictionary&gt;  

            &lt;ResourceDictionary.MergedDictionaries&gt;  

                &lt;ResourceDictionary Source="Gaugestyle.xaml"/&gt;  

                &lt;ResourceDictionary Source="MenuButton.xaml"/&gt;  

            &lt;/ResourceDictionary.MergedDictionaries&gt;  

        &lt;/ResourceDictionary&gt;  

    &lt;/Application.Resources&gt;  

&lt;/Application&gt;  

3、在頁面檔案背景中使用:

ResourceDictionary resources = new ResourceDictionary();  

resources.Source = new Uri("/spjl1;component/MenuButton.xaml", System.UriKind.Relative);  

RadWindow1.Style = resources["ChildWindowStyle1"] as Style;