How would you add command to a wpf button that is part of ItemsControl
and is modifying the ItemsSource
itself?
So here is my XAML:
<ItemsControl ItemsSource="{Binding PluginVMs}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<Button x:Name="btnStampDuplicate"
Content="Duplicate this control"
Command="{Binding ?????????}"/>
<!-- other stuff -->
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
And here is my viewmodel:
public ObservableCollection<PluginViewModel> PluginVMs
{
get { return _pluginVMs; }
set
{
if (_pluginVMs != value)
{
_pluginVMs = value;
NotifyPropertyChanged("PluginVMs");
}
}
}
As you can see PluginVMs
is collection of PluginViewModel
. So I am aware that the Command that is available from the btnStampDuplicate
should be implemented inside of PluginViewModel
.
However, as the name duplicate suggest, I would like to make a duplicated copy of the currently generated PluginViewModel
inside of PluginVMs
. What is the best approach to give that kind of functionality to btnStampDuplicate
?