コード例 #1
0
        public void ValidatesVisualTreeStructure()
        {
            var       factory      = FrameworkElementFactoryExtensions.Create <StackPanel>();
            const int textBoxCount = 5;
            const int buttonCount  = 3;

            factory = factory.AppendNew <TextBox>(textBoxCount).AppendNew <Button>(buttonCount);

            var coreFactory = FrameworkElementFactoryExtensions.Create <StackPanel>();

            coreFactory.AppendChild(factory);

            var dt = new DataTemplate()
            {
                VisualTree = coreFactory
            };

            using (var streamWriter = new StreamWriter(File.Create(@"D:\Samples\visualTreeValidator.xaml")))
            {
                using (var textWriter = new IndentedTextWriter(streamWriter))
                {
                    System.Windows.Markup.XamlWriter.Save(dt, textWriter);
                }
            }

            var treeValidator = new VisualTreeValidator(dt.VisualTree);

            treeValidator.RootElementIs <StackPanel>(cfg =>
            {
                Assert.True(cfg.Nodes <TextBox>().Count() == textBoxCount);
                Assert.True(cfg.Nodes <Button>().Count() == buttonCount);
            });
        }
コード例 #2
0
        public void ChecksRootElement()
        {
            var factory       = FrameworkElementFactoryExtensions.Create <StackPanel>();
            var treeValidator = new VisualTreeValidator(factory);

            Assert.DoesNotThrow(treeValidator.RootElementIs <StackPanel>);
        }
コード例 #3
0
        public void ThrowsOnRootElementMismatch()
        {
            var factory       = FrameworkElementFactoryExtensions.Create <DatePicker>();
            var treeValidator = new VisualTreeValidator(factory);

            Assert.Throws <ArgumentException>(treeValidator.RootElementIs <StackPanel>);
        }
コード例 #4
0
        public void ValidatesVisualTreeStructure()
        {
            var factory = FrameworkElementFactoryExtensions.Create<StackPanel>();
            const int textBoxCount = 5;
            const int buttonCount = 3;
            factory = factory.AppendNew<TextBox>(textBoxCount).AppendNew<Button>(buttonCount);

            var coreFactory = FrameworkElementFactoryExtensions.Create<StackPanel>();
            coreFactory.AppendChild(factory);

            var dt = new DataTemplate() { VisualTree = coreFactory};

            using (var streamWriter = new StreamWriter(File.Create(@"D:\Samples\visualTreeValidator.xaml")))
            {
                using (var textWriter = new IndentedTextWriter(streamWriter))
                {
                    System.Windows.Markup.XamlWriter.Save(dt, textWriter);
                }
            }

            var treeValidator = new VisualTreeValidator(dt.VisualTree);

            treeValidator.RootElementIs<StackPanel>(cfg =>
                                                    {
                                                        Assert.True(cfg.Nodes<TextBox>().Count() == textBoxCount);
                                                        Assert.True(cfg.Nodes<Button>().Count() == buttonCount);
                                                    });
        }
コード例 #5
0
        public void ThrowsOnRootElementMismatch()
        {
            var factory = FrameworkElementFactoryExtensions.Create<DatePicker>();
            var treeValidator = new VisualTreeValidator(factory);

            Assert.Throws<ArgumentException>(treeValidator.RootElementIs<StackPanel>);
        }
コード例 #6
0
        public void ChecksRootElement()
        {
            var factory = FrameworkElementFactoryExtensions.Create<StackPanel>();
            var treeValidator = new VisualTreeValidator(factory);

            Assert.DoesNotThrow(treeValidator.RootElementIs<StackPanel>);
        }
コード例 #7
0
        public void ValidatesBindings()
        {
            var factory = FrameworkElementFactoryExtensions.Create<StackPanel>();
            const int textBoxCount = 5;
            const int buttonCount = 3;
            factory.AppendNew<Button>(buttonCount).AppendNew<TextBox>(textBoxCount);

            var treeValidator = new VisualTreeValidator(factory);

            //treeValidator.RootElementIs<StackPanel>(cfg =>
            //    Assert.DoesNotThrow(cfg.Nodes<Control>().ValidateBindings));
        }
コード例 #8
0
        public void ValidatesBindings()
        {
            var       factory      = FrameworkElementFactoryExtensions.Create <StackPanel>();
            const int textBoxCount = 5;
            const int buttonCount  = 3;

            factory.AppendNew <Button>(buttonCount).AppendNew <TextBox>(textBoxCount);

            var treeValidator = new VisualTreeValidator(factory);

            //treeValidator.RootElementIs<StackPanel>(cfg =>
            //    Assert.DoesNotThrow(cfg.Nodes<Control>().ValidateBindings));
        }
コード例 #9
0
        public void GeneratesTextBlocks()
        {
            WrapInAThread(() =>
            {
                control = new ListBox {
                    DataContext = viewModel
                };
                GenerateTemplate(control);

                using (var streamWriter = new StreamWriter(File.Create(@"D:\Samples\goodTemplate.xaml")))
                {
                    using (var textWriter = new IndentedTextWriter(streamWriter))
                    {
                        System.Windows.Markup.XamlWriter.Save(control.ItemTemplate, textWriter);
                    }
                }

                templateRoot = control.ItemTemplate.VisualTree;
                Assert.IsNotNull(templateRoot);
                var scalarPropertyCount = typeof(PersonViewModel).GetProperties().Length;

                var treeValidator = new VisualTreeValidator(templateRoot);
                try
                {
                    treeValidator.RootElementIs <StackPanel>(
                        cfg =>
                    {
                        Assert.True(cfg.Nodes <TextBlock>().Count() == 2 * scalarPropertyCount);
                        //Assert.DoesNotThrow(cfg.Nodes<Control>().ValidateBindings);
                    });
                }
                catch (Exception e)
                {
                }


                //todo: проверить содержимое дерева - в том числе bindings
            });
        }
コード例 #10
0
        public void GeneratesTextBlocks()
        {
            WrapInAThread(() =>
                              {
                                  control = new ListBox { DataContext = viewModel };
                                  GenerateTemplate(control);

                                  using (var streamWriter = new StreamWriter(File.Create(@"D:\Samples\goodTemplate.xaml")))
                                  {
                                      using (var textWriter = new IndentedTextWriter(streamWriter))
                                      {
                                          System.Windows.Markup.XamlWriter.Save(control.ItemTemplate, textWriter);
                                      }
                                  }

                                  templateRoot = control.ItemTemplate.VisualTree;
                                  Assert.IsNotNull(templateRoot);
                                  var scalarPropertyCount = typeof(PersonViewModel).GetProperties().Length;

                                  var treeValidator = new VisualTreeValidator(templateRoot);
                                  try
                                  {
                                      treeValidator.RootElementIs<StackPanel>(
                                            cfg =>
                                            {
                                                Assert.True(cfg.Nodes<TextBlock>().Count() == 2 * scalarPropertyCount);
                                                //Assert.DoesNotThrow(cfg.Nodes<Control>().ValidateBindings);
                                            });
                                  }
                                  catch (Exception e)
                                  {

                                  }

                                  //todo: проверить содержимое дерева - в том числе bindings
                              });
        }