I'm using DevExpress XAML Framework. In my grid I have CheckBoxSelectorColumn, which is delivered with the Framework (the easiest way to make multiple selection I've found).
I cannot use binding to get SelectedItems, instead in my main.xaml.cs I use [gridName].SelectedItems.
Is there a way to pass SelectedItems to the MainViewModel?
[EDITED]
I'm sorry for that my question was unclear and without code examples. I'm going to provide some parts of my code.
MyUserControl.xaml
<dxg:GridControl Name="grid" SelectionMode="MultipleRow" AutoGenerateColumns="None" EnableSmartColumnsGeneration="false" ItemsSource="{Binding BugList}" Margin="0,0,0,20" Grid.RowSpan="2">
<dxg:GridControl.View>
<dxg:TableView
AllowEditing="False" ShowCheckBoxSelectorColumn="True"
HorizontalScrollbarVisibility="Auto"
/>
</dxg:GridControl.View>
<dxg:GridColumn FieldName="Description" Header="Description"/>
I used ShowCheckBoxSelectorColumn
property to get a column with a checkbox in each row for multiple select.
Disadvantage of the property, and a benefit at the same time, is that selected items cannot be passed through the binding (if my research was correct), but they can be easily passed to the view backend in the following way:
MyUserControl.xaml.cs
public void EntriesHandle_Button()
{
if (grid.SelectedItems.Count != 0)
{
if (DXMessageBox.Show("Do you really want to remove selected Items from your List?", "Question",
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
//remove selected entries
}
}
else { MessageBox.Show("Please select entries", "Warning"); }
}
With grid.SelectedItems
I can get those items were selected in the checkboxColumn in the view.
I wanted to pass SelectedItems to the ViewModel in order reach them from the Button in my RibbonComponent. That was my question.
[SOLUTION]
I used DevExpress.Mvvm.Messenger to call EntriesHandle_Button()
from the RibbonControl:
ribbon.xaml
<dxb:BarButtonItem Name="BRemove" Content="Remove selected">
<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand EventName="ItemClick" Command="{Binding RemoveEntries_OnClick}"/>
</dxmvvm:Interaction.Behaviors>
</dxb:BarButtonItem>
RibbonViewModel.cs
public class RibbonViewModel : ViewModelBase
{
private readonly IRibbonCommands _ribbonCommands;
public RibbonViewModel(IRibbonCommands ribbonCommands)
{
_ribbonCommands = ribbonCommands;
RemoveEntries_OnClick = new DelegateCommand(_ribbonCommands.RemoveEntries);
}
RibbonCommands.cs
public class RibbonCommands : IRibbonCommands
{
public void RemoveEntries()
{
string message = "remove";
Messenger.Default.Send(message);
}
}
MyUserControl.xaml.cs
public partial class MyUserControl: UserControl
{
public MyUserControl()
{
InitializeComponent();
DataContext = new MyUserControlViewModel();
Messenger.Default.Register<string>(this, EntriesHandle_Button);
}
public void EntriesHandle_Button(string message)
{
if (grid.SelectedItems.Count != 0)
{
switch (message)
{
case "remove":
if (DXMessageBox.Show("Do you really want to remove selected Items from your List?", "Question",
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
//remove selected entries
}
break;
}
}
else { MessageBox.Show("Please select entries", "Warning"); }
}
}