7

WPF アプリケーションでは、グローバルな静的リソースを app.xaml に配置できます。

 <Application.Resources>
        <!--Global View Model Locator-->
        <vm:ViewModelLocator x:Key="Locator"
                             d:IsDataSource="True" />
    </Application.Resources>

それはMVVM Lightからのものでした;)。プロジェクトが wpf クラス ライブラリの場合、そのようなグローバルな静的リソースを初期化する適切な方法は何ですか?

4

1 に答える 1

4

以下のように、リソースを使用して ResourceDictionary を作成し、コードを使用して辞書をマージできます。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:vm="clr-namespace:WPFProject.ViewModel"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<vm:ViewModelLocator x:Key="Locator" 
                         d:IsDataSource="True" />

コード:

 Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(
           new Uri("/WPFProject;Component/Resources/ResourceDictionary1.xaml", UriKind.Relative)) as ResourceDictionary);
于 2010-06-25T07:29:59.427 に答える