Friday, September 21, 2012

WP Silverlight: How to programmatically assign ItemTemplate to PanoramaItem?

WP Silverlight: How to programmatically assign ItemTemplate to PanoramaItem?

Situation:
I have a panorama control with 2 panorama items. First item contain the list of options and, if i choose one of them, panorama control should switch to second item. As you understand, the content of second item should be dynamically updated each time. Moreover the ItemTemplate should be different for each option.
My solution:
I decide to create panorama control each time i need to switch (because the only way to switch panorama item programmatically is to change DefaultItem property which requires reload the page or to hide this and show another control). This solution works, but now i need to assign different ItemTemplate for each panorama item. (Templates are in xaml. I need just to assign it).
Questions:
Is my solution correct? And how can i assign ItemTemplate's in code behind?

Answers & Comments...

Answer: 1

I don't think that your solution is good. As you can see in a WP7 Guidelines :

  • Do not use the pivot control for task-based navigation, like in a wizard application.

The same is for Panorama. You'd better navigate to another page, when user selects an item.

See the People hub. You select a person, and the phone shows you person details page.

by : Anton Sizikovhttp://stackoverflow.com/users/555014

Answer: 2

how can i assign ItemTemplate's in code behind?

The solution looks like this:

public void constructUI() {  Panorama panoramactrl = new Panorama();  PanoramaItem panoramaItem = new PanoramaItem(); panoramaItem.Header = "main"; PanoramaItem panoramaItem1 = new PanoramaItem(); panoramaItem1.Header = "not main";  ListBox listBox = new ListBox(); listBox.ItemsSource = CreatePanoramaItems();  DataTemplate itemTmp = (DataTemplate)XamlReader.Load(      @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007"">     <StackPanel Tag=""{Binding id}"">     <TextBlock Text=""{Binding FirstRaw}"" Foreground=""Red"" FontSize=""40"" />     <TextBlock Text=""{Binding SecondRaw}"" Foreground=""Orange"" FontSize=""30"" Margin=""10,0,0,0"" />     </StackPanel>     </DataTemplate>");  listBox.ItemTemplate = itemTmp; panoramaItem.Content = listBox; panoramactrl.Items.Add(panoramaItem); panoramactrl.Items.Add(panoramaItem1); this.LayoutRoot.Children.Add(panoramactrl); 

}

private List<Data> CreatePanoramaItems() {     List<Data> Panoramaitems = null;     Panoramaitems = new List<Data>      {      new Data("123", "456", "1"),     new Data("234", "567", "2"),     new Data("345", "678", "3")     };     return Panoramaitems; } 

Hope this will be helpful for someone.

by : user1528729http://stackoverflow.com/users/1528729




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog