0

我遵循了教程并陷入了配置设置类的创建实例部分。在这里,他们只需在Application.Resources中添加ObjectDataProvider。就我而言,在这种情况下已经有一个ResourceDictionary,我认为这会导致问题。

我的 App.xaml:

<Application x:Class="MyApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:config="clr-namespace:MyApp.ViewModels"
             StartupUri="MainWindow.xaml">

    <Application.Resources>
            <!-- create instance of config-settings class -->
            <ObjectDataProvider x:Key="AppSettingsDataProvider" ObjectType="{x:Type config:AppSettingsManager}"/>

            <ResourceDictionary x:Key="MainDictionary">
                <!-- also not working: -->
                <!--<ObjectDataProvider x:Key="AppSettingsDataProvider" ObjectType="{x:Type config:AppSettingsManager}"/>-->

                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="pack://application:,,,/Folder/file1.xaml" />
                    <ResourceDictionary Source="pack://application:,,,/Folder/file2.xaml" />
                    <!-- <ResourceDictionary Source="{Binding Source={StaticResource AppSettingsDataProvider}, Path=LoadMethod, Mode=OneWay}"/>-->
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
    </Application.Resources>
</Application>

当我运行程序时,我的ResourceDictionary不再加载(Application.Current.Ressources.MergedDictionaries为空),没有ObjectDataProvider一切正常。将ObjectDataProvider放在ResourceDictionary中,就像 post Problems added an ObjectDataProvider in resources中所建议的那样没有帮助(它在Application类中是否不同?)。那么在哪里放置ObjectDataProvider呢?

4

0 回答 0