Skip to content

Instantly share code, notes, and snippets.

@null-loop
Created June 19, 2013 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save null-loop/5818981 to your computer and use it in GitHub Desktop.
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…
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;
}
@xiaoyuandlg
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment