user2055776
user2055776

Reputation: 15

Detect Visual State changes in Win8 Metro Style App and Change Databinding Based on that

I'm not sure if I do it the wrong way or not, I try to find a way to manually change the data binding to the UI based on Visual State, say, if Snapped, UI will use part of the datasource selectively or just use a new set of data, but I want to keep it neat, so I really don't want to maintain 2 sets at the same time.

Is there a way to detect Visual State changes? Or should I find a different approach?

Upvotes: 1

Views: 497

Answers (1)

Jim O'Neil
Jim O'Neil

Reputation: 23764

The following line of code in the constructor of, say, the GroupedItemsPage in the Grid App template demonstrates where you could put your custom binding code. This simple example displays the current VisualState of the app in response to the CurrentStateChanged event:

ApplicationViewStates.CurrentStateChanged += (s, e) => pageTitle.Text = e.NewState.Name;

You could also tap into OrientationChanged for the more specific case of Snapped that you cited

DisplayProperties.OrientationChanged += (s) => pageTitle.Text = DisplayProperties.CurrentOrientation.ToString();

Upvotes: 2

Related Questions