我想弄清楚如何以編程方式在我們的Silverlight 4應用程序運行時應用主題。我認爲這應該與從XAML加載資源字典並將其與應用程序的合併字典合併一樣簡單。這裏是我到目前爲止的代碼:爲什麼XamlReader.Load在Silverlight 4中無法識別我的附屬屬性?
var themeUri = new Uri(
"OurApp;component/Themes/Classic/Theme.xaml", UriKind.Relative);
var resourceInfo = GetResourceStream(themeUri);
using (var stream = resourceInfo.Stream)
{
using (var reader = new StreamReader(stream))
{
var xamlText = reader.ReadToEnd();
var dict = XamlReader.Load(xamlText) as ResourceDictionary;
Resources.MergedDictionaries.Add(dict);
}
}
不幸的是,XamlParseException
呼叫期間提高到XamlReader.Load
:
的附着性能「富」並沒有在類型「欄」中。
這正確連接是正確聲明,並在XAML命名空間聲明正確引用所需的命名空間。如果通過App.xaml標記聲明式加載到合併的字典中,附加的屬性XAML工作得很好。
下面是其中我想在運行時加載XAML的縮寫副本:
<ResourceDictionary xmlns:u="clr-namespace:Company.Product.Utils"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="ControlPanelStyle" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Grid Margin="0" u:Bar.Foo="True">
<!-- Stuff and things -->
<ContentPresenter Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
在運行時加載XAML時,當它工作得很好時,爲什麼不工作的參考附加屬性「靜態」加載?