ContainerFromItem +DataTemplateSelector +QueryableDomainServiceCollectionView

2 posts, 0 answers
  1. leblanc
    leblanc avatar
    56 posts
    Member since:
    Aug 2010

    Posted 11 Feb 2012 Link to this post

    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?
  2. leblanc
    leblanc avatar
    56 posts
    Member since:
    Aug 2010

    Posted 11 Feb 2012 Link to this post

    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.
  3. DevCraft banner
Back to Top