アプリケーションの MainWindow にアタッチされた一連のコマンド バインディングがあるアプリケーションを作成しました。
(コードは簡潔にするために単純化されています)
<Window x:Class="DBBrowser.Design.Project.ProjectView"
...>
<Window.CommandBindings>
<Commands:DataContextCommandBinding Command="ProjectCommands:ProjectRoutedCommands.OpenReferenceList" Executed="OpenReferenceList" CanExecute="CanOpenReferenceList"/>
...
</Window.CommandBindings>
</Window>
プロジェクトの ViewModel 内には、次の 2 つの関数があります。
public bool CanOpenReferenceList(object parameter)
{
return true;
}
public void OpenReferenceList(object parameter)
{
var dockedReferenceList = new DockableUniversalListView()
{
Name = "referenceList",
Title = "Reference List"
};
referenceData = dockedReferenceList.DataContext as ReferenceListViewModel;
if (referenceData != null) referenceData.EvListSelected += WoWObjectListRecieved;
DockedWindows.Add(dockedReferenceList);
}
詳細は省きますが、このコマンドを呼び出すことができるシナリオは 3 つあります。
- アプリケーションのメイン ウィンドウ内の DockableContent として
- DockableContent を含む新しい Window コントロールとして
- AvalonDock を介してウィンドウを「切り離す」ことによって作成された FloatingWindow として
シナリオ #1 と #2 は、次のコマンド バインディングを使用して完全に機能します。
<Button Margin="2" Content="Validate" Height="23" Name="Validate" Width="75"
Command="ProjectCommands:ProjectRoutedCommands.OpenReferenceList"
CommandTarget="{Binding Path=MainWindow.DataContext,Source={x:Static Application.Current}}"
DockPanel.Dock="Left"
CommandParameter="{Binding Path=SelectedWoWObjectList}"
TabIndex="20" HorizontalAlignment="Right"/>
ただし、AvalonDock ウィンドウを「切り離す」と、ボタンが灰色になります。ただし、スタック トレースは、CanExecute() が呼び出され、そのボタンに対して true を返すことを示しましたが、ボタンは無効のままでした。