Win10 UI入门 pivot multiable DataTemplate

Win10 UI入门 pivot multiable DataTemplate_第1张图片

this is a dynamic pivot with sliderable navigation and multiableDatatemplate Control  

看了 alexis 大哥的pivot 动态绑定,和 自己做了一个多模版带滑动导航条的控件

主要继承了DataTemplateSelector

实现 绑定ItemTemplateSelector="{TemplateBinding BodyDataTemplateSelector}"

主要代码

    public class Media : DataTemplateSelector
    {
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            var media = (TestPivot)item;
            DataTemplate template;

            switch (media.BodyItem.MediaType)
            {
                case Enums.Media.BOOK:
                    template = BookTemplate;
                    break;
                case Enums.Media.GAME:
                    template = GameTemplate;
                    break;
                case Enums.Media.MOVIE:
                    template = MovieTemplate;
                    break;
                default:
                    template = BookTemplate;
                    break;
            }

            return template;
        }

        public DataTemplate BookTemplate { get; set; }

        public DataTemplate GameTemplate { get; set; }

        public DataTemplate MovieTemplate { get; set; }
    }
            "BookDataTemplate">
                "{Binding BodyItem.ListData}" Margin="0,5,0,0" Background="Green">
                    
                        
                            "{Binding}" />
                        
                    
                
            
            "GameDataTemplate">
                "Red" Height="120">
                    "{Binding BodyItem.MediaItem}" Margin="0,5,0,0"/>
                
            
            "MovieDataTemplate">
                "{Binding BodyItem.ItemImg}" Stretch="Uniform"/>
            
            
            "mediaDataTemplateSelector"
                BookTemplate="{StaticResource BookDataTemplate}"
                GameTemplate="{StaticResource GameDataTemplate}" 
                MovieTemplate="{StaticResource MovieDataTemplate}" />
            <ctl:WYPanorama                     
                HeaderDataTemplate="{StaticResource DT_HeaderMutil}"
                    HeaderDataItemsSource="{Binding BindData}" 
                    BodyDataTemplateSelector="{StaticResource mediaDataTemplateSelector}"
                    BodyDataItemsSource="{Binding BindData}">
            

 

你可能感兴趣的:(Win10 UI入门 pivot multiable DataTemplate)