コード例 #1
0
        public MainWindowViewModel()
        {
            Items = new ObservableCollection <IListItem>(new List <IListItem>
            {
                new SomeListItem {
                    Color = Brushes.Yellow, Label = "Item One"
                },
                new SomeOtherListItem {
                    Description = "Some useless description for item two", Label = "Item Two"
                },
                new SomeListItem {
                    Color = Brushes.Yellow, Label = "Item Three"
                },
                new SomeOtherListItem {
                    Description = "Some useless description for item four", Label = "Item Four"
                }
            });

            var factory = new ItemTemplateFactory();

            factory.Register(typeof(SomeListItem), (DataTemplate)Application.Current.FindResource("SomeListItem_Template"));
            factory.Register(typeof(SomeOtherListItem), (DataTemplate)Application.Current.FindResource("SomeOtherListItem_Template"));

            ItemTemplateSelector = new ItemTemplateSelector(factory);
        }
コード例 #2
0
 public ItemTemplateSelector(ItemTemplateFactory factory) => _factory = factory ?? throw new ArgumentNullException(nameof(factory));