<xcad:DockingManager Name="myDockingManager" AnchorablesSource="{Binding FooterTools}" DocumentsSource="{Binding MainWindowTools}"
ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}"
avBehav:AvalonDockLayoutSerializer.LoadLayoutCommand="{Binding AdLayout.LoadLayoutCommand}" avBehav:AvalonDockLayoutSerializer.SaveLayoutCommand="{Binding AdLayout.SaveLayoutCommand}">
在另一个地方,我得到了我想加载默认布局的命令:
ViewModel命令:
private RelayCommand _loadDefaultLayoutCommand;
public RelayCommand LoadDefaultLayoutCommand
{
get
{
return _restoreDefaultLayoutCommand ?? (_loadDefaultLayoutCommand= new RelayCommand(() => LoadDefaultLayout())
);
}
}
private object LoadDefaultLayout()
{
;//AdLayout.LoadDefaultLayoutCommand.Execute();
//unfortunately I cannot invoke above command since I need to convey AvalonDockManager as a parameter which is impossible since ViewModel does not know it.
}
我得到了如下定义的AvalonDockViewModel属性:
public AvalonDockLayoutViewModel AdLayout
{
get { return _avalonDockLayout ?? (_avalonDockLayout = new AvalonDockLayoutViewModel()); }
}
我想从ViewModel调用命令来更新View 我认为这些行为可以用作View和ViewModel之间的沟通桥梁。
用于加载layouat并保存我使用的行为,例如对于Load布局我使用了这样的行为:
private static void OnLoadLayoutCommandChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var framworkElement = obj as FrameworkElement;
// Remove the handler if it exist to avoid memory leaks
if (framworkElement != null)
{
framworkElement.Loaded -= OnFrameworkElementLoaded;
var command = e.NewValue as ICommand;
if (command != null)
{
// the property is attached so we attach the Drop event handler
framworkElement.Loaded += OnFrameworkElementLoaded;
}
}
}
因为我有frameworkElement Load事件,所以非常符合逻辑。
是否可以使用行为机制或其他机制按需加载默认布局,例如就我的菜单命令而言?