Want to set visualstate of GridViewItem RRS feed

  • Question

  • Hi

    I am using GridView with GroupStyle to show grid of numbers in my app and I want to disable the VisualStates(like PointerOver and PointerOverPressed) of some items in Grid in codebehind file at runtime. If anyone have solution to do this please suggest me.

    Thanks in advance.



    Saturday, December 29, 2012 6:53 AM

All replies

  • You need to get the default style and remove the code for visual state that you don´t want, for this use the Blend

    Sara Silva
    My blog | My Windows 8 Store Apps Samples | More Samples
    Follow me in Twitter @saramgsilva

    My Windows 8 Store Apps: Female Pill | Galinho (Tic tac Toe) | 24
    My Windows Phone Apps

    (If my reply answers your question, please propose it as an answer because it will help other

    • Edited by saramgsilva Saturday, December 29, 2012 7:56 PM
    Saturday, December 29, 2012 7:56 PM
  • Hi

    To solve the above problem I set the IsEnabledProperty of each item in code behind by using StyleSelector class as below code.

     public class MyStyleSelector : StyleSelector
            protected override Style SelectStyleCore(object item, DependencyObject container)
                var itemText = ((DayLocation)item).Name;
                Style style = new Style(typeof(GridViewItem));
                    style.Setters.Add(new Setter(GridViewItem.IsEnabledProperty (!String.IsNullOrEmpty(itemText))));
                return style;

    but when the Height,Width,ItemWidth & ItemHeight of VariableSizedWrapGrid is not provided then it works fine, and if it sets to some lower value then at the start of app run it gets crashes. I'm not getting why its happening, Is anyone had faced such problem please suggest the solution

    Wednesday, January 2, 2013 5:08 AM