0
綁定問題
我已經創建了一個應用程序,其中有連接到我的應用程序的主窗口的一系列命令綁定:司令部AvalonDock
(代碼簡化爲簡潔起見)
<Window x:Class="DBBrowser.Design.Project.ProjectView"
...>
<Window.CommandBindings>
<Commands:DataContextCommandBinding Command="ProjectCommands:ProjectRoutedCommands.OpenReferenceList" Executed="OpenReferenceList" CanExecute="CanOpenReferenceList"/>
...
</Window.CommandBindings>
</Window>
在該項目的視圖模型是兩個功能:
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
- 作爲FloatingWindow,通過經由AvalonDock
場景#「撕開」的窗口中創建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"/>
但是,當我「撕掉」A valonDock窗口,按鈕灰色。但是,堆棧跟蹤顯示CanExecute()正在被調用,並且該按鈕返回true,但Button仍處於禁用狀態。