Hello
I had a similar problem, and I solved this by creating a control that inherits the GridView control (let's call it MyGridView), where I have a new property (with dependency property) that holds the selected items. Then I attach to the SelectionChanged and set the new SelectedItems-property.
Example:
public class MyDataGrid : DataGrid, INotifyPropertyChanged
{
public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register("SelectedItems", typeof(IList), typeof(MyDataGrid), new PropertyMetadata(null));
public new IList SelectedItems
{
get { return (IList)GetValue(SelectedItemsProperty); }
set
{
SetValue(SelectedItemsProperty, value);
NotifyPropertyChanged("SelectedItems");
}
}
public MyDataGrid()
: base()
{
base.SelectionChanged += new SelectionChangedEventHandler(MyDataGrid_SelectionChanged);
}
private void MyDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
this.SelectedItems = base.SelectedItems;
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String aPropertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(aPropertyName));
}
}
You can now use your control as an ordinary GridView control, with your alterations.
<grid>
<local:mydatagrid selectionmode="Extended" xmlns:local="#unknown">
ItemsSource="{Binding Path=Items, Mode=OneWay}"
SelectedItems="{Binding Path=SelectedItems, Mode=TwoWay}"
Margin="0,0,0,20"/>
<textblock text="{Binding Path=SelectedItems.Count, Mode=OneWay}">
VerticalAlignment="Bottom" />
</textblock></local:mydatagrid></grid>
You can put more specific code into this control, like navigation behaviors, styling and new functionality.
Hope it helps!