So on my WPF I enabled a right click functionality. If the person in the datagrid is rightclicked then you can choose email
and it'll email that person. But Now I want to improve that by having a Multiple select
option available. I'm wondering what's wrong with my binding or am I taking the wrong binding approach.
Code for Single/SelectedItem
public void SendEmail()
{
var vm = new EmailViewModel(Events);
vm.ByIt(SelectedItem.Id);
}
}
xaml side: Binding SelectedItem
<telerik:RadGridView ItemsSource="{Binding Items, IsAsync=True}" SelectedItem="{Binding SelectedItem}">
<telerik:RadGridView.ContextMenu>
<ContextMenu>
<MenuItem Header="Email" cal:Message.Attach="[Click] = [SendEmail()]"/>
</ContextMenu>
</telerik:RadGridView.ContextMenu>
Which works!
This is my attempt below to Upgrade
to multi select Binding
<telerik:RadGridView.ItemContainerStyle>
<Style TargetType="{x:Type telerik:GridViewRow}">
<Setter Property="IsSelected" Value="{Binding Mode=OneWayToSource, Path=SelectYN}"></Setter>
</Style>
</telerik:RadGridView.ItemContainerStyle>
private BindableCollection<PersonDTO> selectYN;
public BindableCollection<PersonDTO> SelectYN
{
get { return selectYN; }
set
{
if (value != selectYN)
{
selectYN = value;
NotifyOfPropertyChange(() => SelectYN);
}
}
}
public void SendEmail()
{
foreach (PersonDTO value in SelectYN)
{
var vm = new EmailViewModel(Events);
vm.ById(value.Id);
Events.PublishOnUIThread(new ShowTabEvent(vm));
}
}
Assuming that your
RadGridView
is inside aListView
, then you need anIList
property to data bind to theListView.SelectedItems
property....