I have problems adding panorama items through code.
Here is test xaml that works.
<controls:Panorama x:Name="pano">
<controls:Panorama.Title>...</controls:Panorama.Title>
<controls:Panorama.Background>...</controls:Panorama.Background>
<local:TestPanoramaItem ...></local:HoroscopePanoramaItem>
<local:TestPanoramaItem ...></local:HoroscopePanoramaItem>
<local:TestPanoramaItem ...></local:HoroscopePanoramaItem>
</controls:Panorama>
TestPanoramaItem is class that inherits from PanoramaItem and in xaml all works fine. Now i want to reorder panorama items through code.
EDIT: I removed items from xaml from now on
I made default order in static string like “pan1,pan2,pan3,…” and on OnNavigatedToHandler (in MainPage) i use code like this:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
String[] order = App.Order.Split(',');
App.items.Clear();
foreach (String o in order)
{
switch (o)
{
case "pan1": App.items.Add(App.pan1); break;
case "pan2": App.items.Add(App.pan2); break;
case "pan3": App.items.Add(App.pan3); break;
...
}
}
pano.Items.Clear();
foreach (TestPanoramaItem ti in App.items)
pano.Items.Add(ti);
base.OnNavigatedTo(e);
}
For the first time called (this is in MainPage) everything looks ok. Panorama works. There I have menu button that navigates to settings where i can change order of items. On OnNavigateFrom handler in settings page i update App.Order static string. After that OnNavigatedTo of main page is called again and everything goes fine (no exceptions) but i cant move panorama and in panorama items layout is broken.
Any help or solutions?
The problem looks to be in part of the code you’re not sharing with us.
Try creating the smallest possible complete example which demonstrates the problem.
There also appears to be some confusion between
TestPanoramaItemandHoroscopePanoramaItemin the code in your question.I can dynamically rearrange standard PanoramaItems without issue.
The following is based on the default Panorama template:
Mainpage.xaml:MainPage.xaml.csApp.xaml.cs: