I have a list with objects that have all a property: IsSelected. Now I try to automatically select the items in a GridView if the property is true.
I tried to override PrepareContainerForItemOverride in the GridView and set a binding to the objects with no success. Any ideas?
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
base.PrepareContainerForItemOverride(element, item);
var listItem = element as GridViewItem;
var binding = new Binding
{
Mode = BindingMode.TwoWay,
Source = item,
Path = new PropertyPath("Selected")
};
if (listItem != null)
listItem.SetBinding(SelectorItem.IsSelectedProperty, binding);
}
I was so close. I just have to set:
..to select all Items.