I need the instance of view in viewmodel to manipulate the element of view from ViewModel. how can I pass the instance of current View (sender) to ViewModel.
<UserControl...>
<br>...<br>
<Button x:Name="btnRemove" Width="100" Height="30"
Content="Remove" Margin="5" Visibility="Hidden"
Command="{Binding CellFrame.WidgetRemoveCommand, Mode=OneWay, Source={StaticResource Locator}}"
CommandParameter="{Binding Mode=OneWay}" />
<br>...<br>
</UserControl>
This passes the instance of viewModel in WidgetRemoveCommand. How to pass the Intance of Usercontrol.
Thanks
In this scenario, you can simply bind the Command property in constructor of user control. Have a locator class which keeps pointer to CellFrame view model.
The CellFrame view model can have a RelayCommand named WidgetRemoveCommand like below:
Now, this relay command has delegate method defined like below:
So, the trick is to send the ‘this’ in command parameter.
Hope this helps.