当前位置: 首页>>代码示例>>C#>>正文


C# ListBox.ApplyTemplate方法代码示例

本文整理汇总了C#中ListBox.ApplyTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.ApplyTemplate方法的具体用法?C# ListBox.ApplyTemplate怎么用?C# ListBox.ApplyTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ListBox的用法示例。


在下文中一共展示了ListBox.ApplyTemplate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DataContexts_Should_Be_Correctly_Set

        public void DataContexts_Should_Be_Correctly_Set()
        {
            var items = new object[]
            {
                "Foo",
                new Item("Bar"),
                new TextBlock { Text = "Baz" },
                new ListBoxItem { Content = "Qux" },
            };

            var target = new ListBox
            {
                Template = new FuncControlTemplate(CreateListBoxTemplate),
                DataContext = "Base",
                DataTemplates = new DataTemplates
                {
                    new FuncDataTemplate<Item>(x => new Button { Content = x })
                },
                Items = items,
            };

            target.ApplyTemplate();

            var dataContexts = target.Presenter.Panel.Children
                .Cast<Control>()
                .Select(x => x.DataContext)
                .ToList();

            Assert.Equal(
                new object[] { items[0], items[1], "Base", "Base" },
                dataContexts);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:32,代码来源:ListBoxTests.cs

示例2: LogicalChildren_Should_Be_Set_For_DataTemplate_Generated_Items

        public void LogicalChildren_Should_Be_Set_For_DataTemplate_Generated_Items()
        {
            var target = new ListBox
            {
                Template = new FuncControlTemplate(CreateListBoxTemplate),
                Items = new[] { "Foo", "Bar", "Baz " },
            };

            target.ApplyTemplate();

            Assert.Equal(3, target.GetLogicalChildren().Count());

            foreach (var child in target.GetLogicalChildren())
            {
                Assert.IsType<ListBoxItem>(child);
            }
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:17,代码来源:ListBoxTests.cs

示例3: Clicking_Item_Should_Select_It

        public void Clicking_Item_Should_Select_It()
        {
            var target = new ListBox
            {
                Template = new ControlTemplate(CreateListBoxTemplate),
                Items = new[] { "Foo", "Bar", "Baz " },
            };

            target.ApplyTemplate();

            target.Presenter.Panel.Children[0].RaiseEvent(new PointerPressEventArgs
            {
                RoutedEvent = InputElement.PointerPressedEvent,
                MouseButton = MouseButton.Left,
            });

            Assert.Equal(0, target.SelectedIndex);
        }
开发者ID:rdterner,项目名称:Perspex,代码行数:18,代码来源:ListBoxTests_Single.cs

示例4: Focusing_Item_With_Arrow_Key_Should_Select_It

        public void Focusing_Item_With_Arrow_Key_Should_Select_It()
        {
            var target = new ListBox
            {
                Template = new ControlTemplate(CreateListBoxTemplate),
                Items = new[] { "Foo", "Bar", "Baz " },
            };

            target.ApplyTemplate();

            target.Presenter.Panel.Children[0].RaiseEvent(new GotFocusEventArgs
            {
                RoutedEvent = InputElement.GotFocusEvent,
                NavigationMethod = NavigationMethod.Directional,
            });

            Assert.Equal(0, target.SelectedIndex);
        }
开发者ID:rdterner,项目名称:Perspex,代码行数:18,代码来源:ListBoxTests_Single.cs

示例5: ListBoxItem_Containers_Should_Be_Generated

        public void ListBoxItem_Containers_Should_Be_Generated()
        {
            var items = new[] { "Foo", "Bar", "Baz " };
            var target = new ListBox
            {
                Template = new FuncControlTemplate(CreateListBoxTemplate),
                Items = items,
            };

            target.ApplyTemplate();

            var text = target.Presenter.Panel.Children
                .OfType<ListBoxItem>()
                .Do(x => x.Template = ListBoxItemTemplate())
                .Do(x => x.ApplyTemplate())
                .Select(x => x.Presenter.Child)
                .OfType<TextBlock>()
                .Select(x => x.Text)
                .ToList();

            Assert.Equal(items, text);
        }
开发者ID:Arlorean,项目名称:Perspex,代码行数:22,代码来源:ListBoxTests.cs

示例6: Setting_SelectedItem_Should_Set_Panel_Keyboard_Navigation

        public void Setting_SelectedItem_Should_Set_Panel_Keyboard_Navigation()
        {
            var target = new ListBox
            {
                Template = new FuncControlTemplate(CreateListBoxTemplate),
                Items = new[] { "Foo", "Bar", "Baz " },
            };

            target.ApplyTemplate();

            target.Presenter.Panel.Children[1].RaiseEvent(new PointerPressEventArgs
            {
                RoutedEvent = InputElement.PointerPressedEvent,
                MouseButton = MouseButton.Left,
            });

            var panel = target.Presenter.Panel;

            Assert.Equal(
                KeyboardNavigation.GetTabOnceActiveElement((InputElement)panel),
                panel.Children[1]);
        }
开发者ID:JackWangCUMT,项目名称:Perspex,代码行数:22,代码来源:ListBoxTests.cs

示例7: Setting_Item_IsSelected_Sets_ListBox_Selection

        public void Setting_Item_IsSelected_Sets_ListBox_Selection()
        {
            var target = new ListBox
            {
                Template = new ControlTemplate(CreateListBoxTemplate),
                Items = new[] { "Foo", "Bar", "Baz " },
            };

            target.ApplyTemplate();

            ((ListBoxItem)target.GetLogicalChildren().ElementAt(1)).IsSelected = true;

            Assert.Equal("Bar", target.SelectedItem);
            Assert.Equal(1, target.SelectedIndex);
        }
开发者ID:rdterner,项目名称:Perspex,代码行数:15,代码来源:ListBoxTests_Single.cs

示例8: Clicking_Selected_Item_Should_Not_Deselect_It_When_SelectionMode_ToggleAlwaysSelected

        public void Clicking_Selected_Item_Should_Not_Deselect_It_When_SelectionMode_ToggleAlwaysSelected()
        {
            var target = new ListBox
            {
                Template = new ControlTemplate(CreateListBoxTemplate),
                Items = new[] { "Foo", "Bar", "Baz " },
                SelectionMode = SelectionMode.Toggle | SelectionMode.AlwaysSelected,
            };

            target.ApplyTemplate();
            target.SelectedIndex = 0;

            target.Presenter.Panel.Children[0].RaiseEvent(new PointerPressEventArgs
            {
                RoutedEvent = InputElement.PointerPressedEvent,
                MouseButton = MouseButton.Left,
            });

            Assert.Equal(0, target.SelectedIndex);
        }
开发者ID:rdterner,项目名称:Perspex,代码行数:20,代码来源:ListBoxTests_Single.cs

示例9: Prepare

        private void Prepare(ListBox target)
        {
            // The ListBox needs to be part of a rooted visual tree.
            var root = new TestRoot();
            root.Child = target;

            // Apply the template to the ListBox itself.
            target.ApplyTemplate();

            // Then to its inner ScrollViewer.
            var scrollViewer = (ScrollViewer)target.GetVisualChildren().Single();
            scrollViewer.ApplyTemplate();

            // Then make the ScrollViewer create its child.
            ((ContentPresenter)scrollViewer.Presenter).UpdateChild();

            // Now the ItemsPresenter should be reigstered, so apply its template.
            target.Presenter.ApplyTemplate();

            // Because ListBox items are virtualized we need to do a layout to make them appear.
            target.Measure(new Size(100, 100));
            target.Arrange(new Rect(0, 0, 100, 100));

            // Now set and apply the item templates.
            foreach (ListBoxItem item in target.Presenter.Panel.Children)
            {
                item.Template = ListBoxItemTemplate();
                item.ApplyTemplate();
                item.Presenter.ApplyTemplate();
                ((ContentPresenter)item.Presenter).UpdateChild();
            }

            // The items were created before the template was applied, so now we need to go back
            // and re-arrange everything.
            foreach (IControl i in target.GetSelfAndVisualDescendents())
            {
                i.InvalidateMeasure();
            }

            target.Arrange(new Rect(0, 0, 100, 100));
        }
开发者ID:akrisiun,项目名称:Avalonia,代码行数:41,代码来源:ListBoxTests.cs

示例10: Removing_SelectedItem_Should_Clear_TabOnceActiveElement

        public void Removing_SelectedItem_Should_Clear_TabOnceActiveElement()
        {
            var items = new ObservableCollection<string>(new[] { "Foo", "Bar", "Baz " });

            var target = new ListBox
            {
                Template = Template(),
                Items = items,
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            target.Presenter.Panel.Children[1].RaiseEvent(new PointerPressedEventArgs
            {
                RoutedEvent = InputElement.PointerPressedEvent,
                MouseButton = MouseButton.Left,
            });

            items.RemoveAt(1);

            var panel = target.Presenter.Panel;

            Assert.Null(KeyboardNavigation.GetTabOnceActiveElement((InputElement)panel));
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:25,代码来源:SelectingItemsControlTests.cs

示例11: Nested_ListBox_Does_Not_Change_Parent_SelectedIndex

        public void Nested_ListBox_Does_Not_Change_Parent_SelectedIndex()
        {
            SelectingItemsControl nested;

            var root = new SelectingItemsControl
            {
                Template = Template(),
                Items = new IControl[]
                {
                    new Border(),
                    nested = new ListBox
                    {
                        Template = Template(),
                        Items = new[] { "foo", "bar" },
                        SelectedIndex = 1,
                    }
                },
                SelectedIndex = 0,
            };

            root.ApplyTemplate();
            root.Presenter.ApplyTemplate();
            nested.ApplyTemplate();
            nested.Presenter.ApplyTemplate();

            Assert.Equal(0, root.SelectedIndex);
            Assert.Equal(1, nested.SelectedIndex);

            nested.SelectedIndex = 0;

            Assert.Equal(0, root.SelectedIndex);
        }
开发者ID:CarlSosaDev,项目名称:Avalonia,代码行数:32,代码来源:SelectingItemsControlTests.cs

示例12: ApplyTemplate

        private void ApplyTemplate(ListBox target)
        {
            // Apply the template to the ListBox itself.
            target.ApplyTemplate();

            // Then to its inner ScrollViewer.
            var scrollViewer = (ScrollViewer)target.GetVisualChildren().Single();
            scrollViewer.ApplyTemplate();

            // Then make the ScrollViewer create its child.
            ((ContentPresenter)scrollViewer.Presenter).UpdateChild();

            // Now the ItemsPresenter should be reigstered, so apply its template.
            target.Presenter.ApplyTemplate();
        }
开发者ID:KvanTTT,项目名称:Perspex,代码行数:15,代码来源:ListBoxTests_Single.cs


注:本文中的ListBox.ApplyTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。