I have a window that is created at runtime that contains a UserControl. That UserControl has a reference to a command on the window:
...
<Button>
Command="{Binding DataContext.ReturnCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type views:EditCartView}}, Mode=OneWay}"
</Button>
...
This works as expected, when the button is clicked, the command is called from the EditCartView window ViewModel. But I was wondering is it possible to call the same command using ElementName? Something like this:
<Button>
Command="{Binding DataContext.ReturnCommand, ElementName=EditCartWindow, Mode=OneWay}"
</Button>
and with setting the name on the window:
<Window x:Class="Views.EditCartView"
Name="EditCartWindow"
...
I have tried calling RegisterName("EditCartWindow", this);
in the EditCartView constructor with no luck.
Thank you for your help.