我上课DesignerCanvas
,我有RoutedCommand
。
public class DesignerCanvas
{
public static RoutedCommand SelectAll = new RoutedCommand();
public DesignerCanvas()
{
this.CommandBindings.Add(new CommandBinding(DesignerCanvas.SelectAll, SelectAll_Executed));
SelectAll.InputGestures.Add(new KeyGesture(Key.A, ModifierKeys.Control));
}
}
在ResourcesDictionary
我已经获得了MyToolbar
这个我已经指定了如下命令的按钮:
<Button Margin="3" Width="55" Style="{StaticResource ToolBarButtonBaseStyle}"
HorizontalContentAlignment="Center"
Command="{x:Static DesignerCanvas.SelectAll}"
CommandTarget="{Binding ElementName=MyDesigner} /">
除非我不关闭主窗口而不是使用new MainWindow().Show()
再次创建窗口,否则一切都会完美无缺。所有命令都希望在旧DesignerCanvas
中执行(来自原始MainWindow
)如何在新CommandTarget
中创建将DesignerCanvas
更改为新MainWindow
女巫的操作?
修改
MyDesigner
中的 MainWindow
:
<s:DesignerCanvas
Focusable="true"
x:Name="MyDesigner"
Background="{StaticResource WindowBackgroundBrush}"
ContextMenu="{StaticResource DesignerCanvasContextMenu}"
SnapsToDevicePixels="True"
Margin="-2" />