This is a migrated thread and some comments may be shown as answers.

IsContentPreserved Bug

3 Answers 96 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Krasimir
Top achievements
Rank 1
Krasimir asked on 01 Nov 2011, 05:45 PM
I have the following problem.
I have a navigation conception that when I navigate to new page, a new RadTabItem is created and the content of the Silverlight Page is loaded in that tab item. Here is my sample xaml:

<UserControl.Resources>
    <DataTemplate x:Key="panelBarItemTemplate">
        <TextBlock Text="{Binding Content}"
                    Tag="{Binding Uri}" />
    </DataTemplate>
</UserControl.Resources>
 
<telerik:RadTabControl HorizontalAlignment="Stretch"
                        Name="radTabControlResultset"
                        SupressSelectedContentTemplateReapplying="True"
                        IsContentPreserved="True"
                        SelectionChanged="radTabControlResultset_SelectionChanged">
    <telerik:RadTabControl.ContentTemplate>
        <DataTemplate>
            <navigation:Frame x:Name="ContentFrame"
                                Source="{Binding NavigateUri}"
                                UriMapper="{StaticResource SilverlightUriMappings}">
            </navigation:Frame>
        </DataTemplate>
    </telerik:RadTabControl.ContentTemplate>
</telerik:RadTabControl>
 
<telerik:RadPanelBar Name="panelBarNavigation"
                        HorizontalAlignment="Left"                                            
                        ItemTemplate="{StaticResource panelBarItemTemplate}"
                        ItemClick="panelBarNavigation_ItemClick">
</telerik:RadPanelBar>

#region class definitions  
 public class Navigation
    {
        public object Content { get; set; }
        public object Uri { get; set; }
    }
 
    public class TabItem
    {
        public object NavigateUri { get; set; }
    }
#endregion
 
#region Code Behind
 
public List<Navigation> NavSource { get; set; }
public ObservableCollection<TabItem> TabItems { get; set; }
 
panelBarNavigation.ItemsSource = NavSource;
radTabControlResultset.ItemsSource = TabItems;
 
private void panelBarNavigation_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    var uri = new Uri(((Navigation)((RadPanelBarItem)e.OriginalSource).Header).Uri.ToString(), UriKind.RelativeOrAbsolute);
    var newItem = new TabItem{NavigateUri = uri};
             
    TabItems.Add(newItem);
}
#endregion

So I have different URLs for the different tabs. But I have the ability to open 1 Page several times in different tabs. It's working when IsPreservedContent = "False" as default, but that way I cannot open 1 page several times with diffrent context. When I set IsPreservedContent = "True" I am able to open the page several times with different context, but I'm only able to open the first page that I select. When I try to open s.th. else, the first page (that I opened) loads in the tab. I can send you a sample application if needed. I don't know whether this is how it's supposed to work. Can you give me a clue?

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 04 Nov 2011, 01:01 PM
Hi Krasimir,

Basically when you use  the Frame control it expects its source to change so that the user can navigate through different pages. However, when you place the Frame control inside a RadTabControl, you don't change the Frame's source but the RadTabControl selection thus displaying different instances of a Frame control. And this along with the settings of the RadTabControl causes the behavior you described.

So it might be better to use only the Navigation framework defining Hyperlink buttons to switch the Frame's Source. Or you can use only the RadTabControl and go entirely with databinding - creating different ControlTemplates to display different content for each RadTabItem. I attached a sample project that illustrates how to implement such an approach. Please give it a try and let us know if it is applicable in your case.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Krasimir
Top achievements
Rank 1
answered on 07 Nov 2011, 10:35 AM
Thank you for your reply!
I'm aware of these two methods, but what I wanted to do is to combine both of them, i.e. I want to use the navigation framework or s.th. else to change the URL for every different tab item of the tab control. Actually I succeeded to do that, but I run across an error when I open the same page several times in different tab items. To do that I set IsContentPreserved = "True" and that is when the error encounter! Please, refer to the code I posted at the begining to recreate the problem and let me know if you want further explanations.

All the best,
Krasimir
0
Tina Stancheva
Telerik team
answered on 10 Nov 2011, 11:00 AM
Hello Krasimir,

Thank you for getting back to us and elaborating on your requirements.

You can define a Frame in the RadTabItems Content and it can behave as you want it to but you'll need to set the Frame JournalOwnership property to OwnsJournal.  By default the property is set to Automatic, which means that the frame integrates with the browser history journal.  However, when all frames in the application are integrated with the browser history journal each would navigate to the same page based on the browser history journal thus causing the unexpected behavior you described.

However, setting the Frame.JournalOwnership property to OwnsJournal means that each frame maintains its own navigation journal and you will be able to use the different frames in the different TabItems to display their own set of pages independently. Still, you'll need to keep in mind that setting the JournalOwnership to OwnsJournal basically disables frame responding to UriMapping rules and you'll need to use the Navigate() method to navigate through pages.

I modified my solution to illustrate this approach. Please give it a try and let me know if it helps.

Kind regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TabControl
Asked by
Krasimir
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Krasimir
Top achievements
Rank 1
Share this question
or