0

ウィンドウの別の XAML ファイルで DataContext のアプリケーション リソースを使用する際に問題が発生しています。(DataContext は MVVM ViewModel です。) Google と SO を検索しましたが、私がしていることは正しいはずです。App.xaml コードは次のとおりです。

<Application x:Class="Test.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:ViewModel="clr-namespace:Test.ViewModel;assembly=Test.ViewModel"
             Startup="Application_Startup">
    <Application.Resources>
        <ViewModel:DocumentManager x:Key="DocumentManagerViewModel" />
    </Application.Resources>
</Application>

ここに私の MainWindow.xaml の一部があります:

<ribbon:Ribbon>   
    <ribbon:Ribbon.ApplicationMenu>
        <ribbon:RibbonApplicationMenu SmallImageSource="..\Images\SmallIcon.png"
                                      DataContext="{Binding Source={StaticResource DocumentManagerViewModel}}">
        </ribbon:RibbonApplicationMenu>
    </ribbon:Ribbon.ApplicationMenu>
</ribbon:Ribbon>

これを実行すると、次の XamlParseException が発生します。

「'System.Windows.StaticResourceExtension' に値を指定すると、例外がスローされました。」行番号「31」および行位置「47」。

私も試しました:

DataContext="{StaticResource DocumentManagerViewModel}"

4

0 に答える 0