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

ContainerFromItem +DataTemplateSelector +QueryableDomainServiceCollectionView

1 Answer 64 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
leblanc
Top achievements
Rank 1
leblanc asked on 11 Feb 2012, 07:00 PM
Previously we hard several nested RadTabControl (s) and had defined IsXXSelected for each RadTabItem.

What I've done now is

                                ItemsSource="{Binding AvailableTabs}"
                                SelectedItem="{Binding SelectedTab, Mode=TwoWay}"
                                 ItemTemplateSelector="{StaticResource _TabControlItemTemplateSelector}"
                                ContentTemplateSelector="{StaticResource _TabControlContentTemplateSelector}"




public class ResourceTemplateSelector : DataTemplateSelector
{
    public ResourceTemplateSelector()
    {
        Resources = new ResourceDictionary();
    }
 
    public ResourceDictionary Resources { get; set; }
 
    public Dictionary<object, DataTemplate> _cache = new Dictionary<object, DataTemplate>();
 
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        var original = base.SelectTemplate(item, container);
 
        if(_cache.ContainsKey(item))
        {
            return _cache[item];
        }
 
        string contentTypeName = item.GetType().Name;
        var contentTemplate = Resources[contentTypeName] as DataTemplate;
 
        _cache.Add(item, contentTemplate);
 
        return contentTemplate;
    }
}



After this change I noticed when AutoLoad == true on QueryableDomainServiceCollectionView is making requests as *TemplateSelector generates a new container item.

This occurs because the view being regenerated has:

                        <telerikGrid:RadGridView.SortDescriptors>
                            <Data:SortDescriptor Member="Score"
                                            SortDirection="Ascending" />
                        </telerikGrid:RadGridView.SortDescriptors>

Which affects SortDescriptors therefore triggering AutoLoad.


As you can see above I assumed it is because the ContainerFromItem must be generating a new one from *TemplateSelector so I tried caching the DataTemplate.  I tried using base.SelectTemplate however it is always null.  I also could not find any visualization setting on RadTabControl to disable removing generated container view.

These efforts did not solve the problem. 

Any ideas on how i can resolve this problem when using DataTemplateSelector?

1 Answer, 1 is accepted

Sort by
0
leblanc
Top achievements
Rank 1
answered on 12 Feb 2012, 02:58 AM
I worked on another feature and when i came back discovered:
   IsContentPreserved="True"

http://www.telerik.com/help/silverlight/radtabcontrol-how-to-keep-content.html

which solves my exact problem.
Tags
TabControl
Asked by
leblanc
Top achievements
Rank 1
Answers by
leblanc
Top achievements
Rank 1
Share this question
or