使用单独的.xaml文件来使用WP8应用程序中的资源

使用单独的.xaml文件来使用WP8应用程序中的资源,xaml,windows-phone-8,Xaml,Windows Phone 8,我想使用外部文件在我的应用程序上自定义样式,但它不起作用。我遵循这一点,但当我执行项目时,例外情况会出现: System.Windows.ni.dll中出现“System.Windows.Markup.XamlParseException”类型的第一次意外异常 我的XAML代码: app.xaml: <Application.Resources> <local:LocalizedStrings xmlns:local="clr-namespace:App1" x:Key

我想使用外部文件在我的应用程序上自定义样式,但它不起作用。我遵循这一点,但当我执行项目时,例外情况会出现:

System.Windows.ni.dll中出现“System.Windows.Markup.XamlParseException”类型的第一次意外异常

我的XAML代码:

app.xaml:

<Application.Resources>
    <local:LocalizedStrings xmlns:local="clr-namespace:App1" x:Key="LocalizedStrings"/>
    <ResourceDictionary x:Key="myDict">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Resources.xaml:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style TargetType="TextBox" x:Key="MyTextBox">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="0.5"/>
        <Setter Property="BorderBrush" Value="Gray"/>
        <Setter Property="Opacity" Value="0.5"/>
        <Setter Property="Foreground" Value="Red"/>
    </Style>

</ResourceDictionary>

尝试将您的本地资源声明移动到您正在创建并分配给
应用程序的
ResourceDictionary
中。Resources
属性:

<Application.Resources>
    <ResourceDictionary x:Key="myDict">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources.xaml"/>
        </ResourceDictionary.MergedDictionaries>

        <local:LocalizedStrings xmlns:local="clr-namespace:App1" x:Key="LocalizedStrings"/>
        <!-- other resources in here -->
    </ResourceDictionary>
</Application.Resources>

感谢您的全面回答,但这样一来,标签ResourceDictionary就不能使用属性x:Key。移除此属性后,一切正常。顺致敬意,