AnjumSKhan
AnjumSKhan

Reputation: 9827

How we can access VisualStateGroup of a Control

I saw this page. And I started wondering how I can access VisualStateGroup of a DataGrid, or of a Button from code ?

Upvotes: 0

Views: 138

Answers (1)

Il Vic
Il Vic

Reputation: 5666

You can use the GetVisualStateGroups method of VisualStateManager.

If button is the name of your control:

IList list = VisualStateManager.GetVisualStateGroups(button);
if (list.Count > 0)
{
    VisualStateGroup visualStateGroup = (VisualStateGroup)list[0];
    foreach (VisualState visualState in visualStateGroup.States)
    {
        // put here your logic
    }
}

Indeed list is an ObservableCollection, while States is a FreezableCollection. I hope it can help you.

Upvotes: 2

Related Questions