Created
June 19, 2013 23:15
-
-
Save null-loop/5818981 to your computer and use it in GitHub Desktop.
Having to add this to pages that host panoramas to work around this bug - https://connect.microsoft.com/VisualStudio/feedback/details/772715/wp8-panorama-using-itemssource-does-not-keep-track-of-selectedindex - what's the point of data binding if it's not universal? Basically you can't databind a panorama control in WP8 and expect it to work - 7…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void WirePanorama(ObservableCollection<Screen> topNavItems) | |
{ | |
Dispatcher.BeginInvoke(() => | |
{ | |
Panorama.Items.Clear(); | |
foreach (var pi in topNavItems.Select(CreatePanoramaItemForViewModel)) | |
{ | |
Panorama.Items.Add(pi); | |
} | |
}); | |
} | |
private static PanoramaItem CreatePanoramaItemForViewModel(Screen screen) | |
{ | |
return new PanoramaItem | |
{ | |
Header = new TextBlock() | |
{ | |
Text = screen.DisplayName, | |
FontSize = 72, | |
FontWeight = FontWeights.ExtraLight, | |
Foreground = new SolidColorBrush((Color) Application.Current.Resources["PhoneAccentColor"]) | |
}, | |
Content = CreateControlForViewModel(screen) | |
}; | |
} | |
private static object CreateControlForViewModel(Screen screen) | |
{ | |
var c = ViewLocator.LocateForModelType(screen.GetType(), null, null); | |
ViewModelBinder.Bind(screen, c, null); | |
return c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like very powerful code. I am also very interested in some UI panorama, and I recently got a panorama control tutorial, but not quite understand the .NET environment.