Take the 2-minute tour ×

My question is about the ItemTemplateSelector.

I have a property called State in my model and depending on the State I apply two differents styles. I use SQLite for the data but the property State is marked with the attribute [ignore] from SQLite.

I need to change the style when I click the item in the GridView.

private void productsDG_ItemClick(object sender, ItemClickEventArgs e)
    var clickitem = ((Product)e.ClickedItem);
    clickitem.State = true; 

Changing the state of the GridView does not update the DataTemplate for the item. (The DataTemplate works fine, I tested it with the two states).

The custom data template is:

public class CustomDataTemplateSelector : DataTemplateSelector
    public DataTemplate defaultTemplate { get; set; }
    public DataTemplate unavailable { get; set; }

    protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        Product prod = (Product)item;
        if (prod.State == true)
            return defaultTemplate;

        return unavailable;
share|improve this question
please post your xaml code. –  RAZER Apr 15 at 6:53

1 Answer 1

up vote 0 down vote accepted

clickitems class, whatever it is, must implement the INotifyPropertyChanged interface and the State property must fire change notification when set. Otherwise WPF won't know you changed the value of the property and won't update the bound control(s). If it doesn't, you could call UpdateTarget() on the bound control(s)' BindingExpression after setting State, but at that point, does using data binding still make sense?

share|improve this answer

Your Answer


