当我使用 ResourceDictionary 的代码执行 Silverlight 应用程序时,我得到了这个异常:
System.Windows.Markup.XamlParseException occurred.
Failed to assign to property 'System.Windows.ResourceDictionary.Source' [Line: 9 Position:35]
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at MyApp.Silverlight.App.InitializeComponent()
at MyApp.Silverlight.App..ctor()
StyleResources.xaml:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MyApp.Silverlight.StyleResources"
x:ClassModifier="public">
StyleResources.xaml.cs:
namespace MyApp.Silverlight
{
public partial class StyleResources : ResourceDictionary
{
public StyleResources()
{
InitializeComponent();
}
}
}
从其他 stackoverflow 帖子中可以看出,这就是我将 ResourceDictionary 包含到 MainPage.xaml 中的方式:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
x:Class="MyApp.Silverlight.MainPage"
mc:Ignorable="d" d:DesignWidth="944" d:DesignHeight="592"
xmlns:resource="clr-namespace:MyApp.Silverlight;assembly=MyApp.Silverlight"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
<UserControl.Resources>
<ResourceDictionary x:Key="resourcestyles">
<ResourceDictionary.MergedDictionaries>
<resource:StyleResources />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
谁能告诉我这里出了什么问题?