如何更改CommandTarget

时间:2014-10-06 17:27:21

标签: c# wpf routed-commands

我上课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" />

0 个答案:

没有答案