I have class DesignerCanvas
where I have 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));
}
}
In ResourcesDictionary
I've got MyToolbar
in this I've got buttons that have specify commands like this:
<Button Margin="3" Width="55" Style="{StaticResource ToolBarButtonBaseStyle}"
HorizontalContentAlignment="Center"
Command="{x:Static DesignerCanvas.SelectAll}"
CommandTarget="{Binding ElementName=MyDesigner} /">
And everything works perfect unless I don't close main window and than create it ones again with new MainWindow().Show()
. All commands want to execute in old DesignerCanvas
(from the original MainWindow
) What can I do to change CommandTarget
to new DesignerCanvas
witch was created in new MainWindow
?
EDIT
MyDesigner
in MainWindow
:
<s:DesignerCanvas
Focusable="true"
x:Name="MyDesigner"
Background="{StaticResource WindowBackgroundBrush}"
ContextMenu="{StaticResource DesignerCanvasContextMenu}"
SnapsToDevicePixels="True"
Margin="-2" />