4

外部ファイルを使用してアプリのスタイルをカスタマイズしたいのですが、うまくいきません。私はこのステップバイステップに従っていますが、プロジェクトの例外を実行すると、次のようになります。

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>
4

1 に答える 1

5

ローカル リソース宣言を、作成してプロパティResourceDictionaryに割り当てている内に移動してみてください。Application.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>
于 2013-02-12T02:57:32.147 に答える