/// <summary>
 /// Initializes a new instance of the <see cref="OverriddenTimePicker"/> class.
 /// </summary>
 /// <param name="useOverriddenTimeUpDownTemplate">If set to <c>True</c> use overridden time up down template.</param>
 public OverriddenTimePicker(bool useOverriddenTimeUpDownTemplate) : base()
 {
     if (useOverriddenTimeUpDownTemplate)
     {
         XamlBuilder<ControlTemplate> template = new XamlBuilder<ControlTemplate>
                                                     {
                                                             Name = "controlTemplate",
                                                             ExplicitNamespaces = new Dictionary<string, string>
                                                                                      {
                                                                                              {
                                                                                                      "ctrl", XamlBuilder.GetNamespace(GetType())
                                                                                              }
                                                                                      },
                                                             AttributeProperties = new Dictionary<string, string>
                                                                                       {
                                                                                               {
                                                                                                       "TargetType", "ctrl:" + GetType().Name
                                                                                               }
                                                                                       },
                                                             Children = new List<XamlBuilder>
                                                                            {
                                                                                    new XamlBuilder<OverriddenTimeUpDown>
                                                                                        {
                                                                                                Name = "TimeUpDown"
                                                                                        }
                                                                            }
                                                     };
         Template = template.Load();
     }
 }
        public void StyleBackgroundInXaml()
        {
            WrapPanel panel = DefaultWrapPanelToTest;
            panel.Height = 400;
            panel.Width = 600;

            XamlBuilder<Style> styleBuilder = new XamlBuilder<Style>
            {
                ExplicitNamespaces = new Dictionary<string, string> { { "controlsToolkit", XamlBuilder.GetNamespace(typeof(WrapPanel)) } },
                AttributeProperties = new Dictionary<string, string> { { "TargetType", "controlsToolkit:WrapPanel" } },
                Children = new List<XamlBuilder>
                {
                    new XamlBuilder<Setter>
                    {
                        AttributeProperties = new Dictionary<string, string> { { "Property", "Background" } },
                        ElementProperties = new Dictionary<string, XamlBuilder>
                        {
                            {
                                "Value",
                                new XamlBuilder<SolidColorBrush>
                                {
                                    AttributeProperties = new Dictionary<string, string> { { "Color", "Gray" } }
                                }
                            }
                        }
                    }
                }
            };

            TestAsync(
                panel,
                () => panel.Style = styleBuilder.Load());
        }
        public virtual void GetItemsHostIsCorrectPanel()
        {
            string       name    = "DesiredPanel";
            ItemsControl control = new ItemsControl {
                ItemsSource = new[] { 1, 2, 3, 4, 5 }
            };
            Panel host = null;
            XamlBuilder <ItemsPanelTemplate> builder = new XamlBuilder <ItemsPanelTemplate>
            {
                Children = new List <XamlBuilder>
                {
                    new XamlBuilder <StackPanel> {
                        Name = name
                    }
                }
            };

            control.ItemsPanel = builder.Load();

            TestAsync(
                control,
                () => host = control.GetItemsHost(),
                () => Assert.IsNotNull(host, "Failed to find ItemsHost!"),
                () => Assert.AreEqual(name, host.Name, "ItemsHost name did not match!"));
        }
        public virtual void FindNameWorksOnViewboxChild()
        {
            XamlBuilder xaml = new XamlBuilder <Viewbox>()
            {
                ExplicitNamespaces = new Dictionary <string, string> {
                    { "controls", XamlBuilder.GetNamespace(typeof(Viewbox)) }
                },
                Children = new List <XamlBuilder>
                {
                    new XamlBuilder <TextBlock>
                    {
                        Name = "Foo",
                        AttributeProperties = new Dictionary <string, string> {
                            { "Text", "Test" }
                        }
                    }
                }
            };

            Viewbox   view = xaml.Load() as Viewbox;
            TextBlock text = null;

            TestAsync(
                view,
                () => text = view.FindName("Foo") as TextBlock,
                () => Assert.IsNotNull(text, "Failed to find named Child!"));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OverriddenTimePicker"/> class.
 /// </summary>
 /// <param name="useOverriddenTimeUpDownTemplate">If set to <c>True</c> use overridden time up down template.</param>
 public OverriddenTimePicker(bool useOverriddenTimeUpDownTemplate) : base()
 {
     if (useOverriddenTimeUpDownTemplate)
     {
         XamlBuilder <ControlTemplate> template = new XamlBuilder <ControlTemplate>
         {
             Name = "controlTemplate",
             ExplicitNamespaces = new Dictionary <string, string>
             {
                 {
                     "ctrl", XamlBuilder.GetNamespace(GetType())
                 }
             },
             AttributeProperties = new Dictionary <string, string>
             {
                 {
                     "TargetType", "ctrl:" + GetType().Name
                 }
             },
             Children = new List <XamlBuilder>
             {
                 new XamlBuilder <OverriddenTimeUpDown>
                 {
                     Name = "TimeUpDown"
                 }
             }
         };
         Template = template.Load();
     }
 }
Пример #6
0
        public static HierarchicalDataTemplate GetDataTemplate()
        {
            string templateKey = "template";

            // Wrap the template in a Grid because the XAML parser doesn't like
            // namespaces declared on a DataTemplate
            XamlBuilder <Grid> builder = new XamlBuilder <Grid>
            {
                ExplicitNamespaces = new Dictionary <string, string>
                {
                    { "common", XamlBuilder.GetNamespace(typeof(HierarchicalDataTemplate)) },
                    { "ctl", XamlBuilder.GetNamespace(typeof(TreeViewItem)) },
                    { "sys", XamlBuilder.GetNamespace(typeof(int)) }
                },
                ElementProperties = new Dictionary <string, XamlBuilder>
                {
                    {
                        "Resources",
                        new XamlBuilder <HierarchicalDataTemplate>
                        {
                            Key = templateKey,
                            AttributeProperties = new Dictionary <string, string>
                            {
                                { "ItemsSource", "{Binding Children}" }
                            },
                            Children = new List <XamlBuilder>
                            {
                                new XamlBuilder <ContentControl>
                                {
                                    Name = "TemplateContent",
                                    AttributeProperties = new Dictionary <string, string>
                                    {
                                        { "Content", "{Binding Element}" },
                                        { "Foreground", "Red" }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            Grid container = builder.Load();

            return(container.Resources[templateKey] as HierarchicalDataTemplate);
        }
        public void StyleBackgroundInXaml()
        {
            WrapPanel panel = DefaultWrapPanelToTest;

            panel.Height = 400;
            panel.Width  = 600;

            XamlBuilder <Style> styleBuilder = new XamlBuilder <Style>
            {
                ExplicitNamespaces = new Dictionary <string, string> {
                    { "controlsToolkit", XamlBuilder.GetNamespace(typeof(WrapPanel)) }
                },
                AttributeProperties = new Dictionary <string, string> {
                    { "TargetType", "controlsToolkit:WrapPanel" }
                },
                Children = new List <XamlBuilder>
                {
                    new XamlBuilder <Setter>
                    {
                        AttributeProperties = new Dictionary <string, string> {
                            { "Property", "Background" }
                        },
                        ElementProperties = new Dictionary <string, XamlBuilder>
                        {
                            {
                                "Value",
                                new XamlBuilder <SolidColorBrush>
                                {
                                    AttributeProperties = new Dictionary <string, string> {
                                        { "Color", "Gray" }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            TestAsync(
                panel,
                () => panel.Style = styleBuilder.Load());
        }
        public virtual void GetScrollHostWithNoItemsHost()
        {
            ListBox control = new ListBox {
                ItemsSource = new[] { 1, 2, 3, 4, 5 }
            };
            XamlBuilder <ControlTemplate> builder = new XamlBuilder <ControlTemplate>
            {
                AttributeProperties = new Dictionary <string, string> {
                    { "TargetType", "ListBox" }
                },
                Children = new List <XamlBuilder> {
                    new XamlBuilder <TextBlock>()
                }
            };

            control.Template = builder.Load();
            ScrollViewer host = null;

            TestAsync(
                control,
                () => host = control.GetScrollHost(),
                () => Assert.IsNull(host, "Should not have found ScrollHost!"));
        }
        public virtual void ApplyHierarchicalDataTemplateWithStyle()
        {
            XamlBuilder<Grid> builder = new XamlBuilder<Grid>
            {
                ExplicitNamespaces = new Dictionary<string, string>
                {
                    { "common", XamlBuilder.GetNamespace(typeof(HierarchicalDataTemplate)) },
                    { "ctl", XamlBuilder.GetNamespace(typeof(TreeViewItem)) },
                    { "sys", XamlBuilder.GetNamespace(typeof(int)) }
                },
                ElementProperties = new Dictionary<string, XamlBuilder>
                {
                    {
                        "Resources",
                        new XamlBuilder<Style>
                        {
                            Key = "itemStyle",
                            AttributeProperties = new Dictionary<string, string> { { "TargetType", "ctl:TreeViewItem" } },
                            Children = new List<XamlBuilder>
                            {
                                new XamlBuilder<Setter>
                                {
                                    AttributeProperties = new Dictionary<string, string> 
                                    {
                                        { "Property", "FontSize" },
                                        { "Value", "15" }
                                    }
                                }
                            }
                        }
                    }
                },
                Children = new List<XamlBuilder>
                {
                    new XamlBuilder<Grid>
                    {
                        ElementProperties = new Dictionary<string, XamlBuilder>
                        {
                            {
                                "Resources",
                                new XamlBuilder<HierarchicalDataTemplate>
                                {
                                    Key = "template",
                                    AttributeProperties = new Dictionary<string, string>
                                    {
                                        { "ItemsSource", "{Binding Children}" },
                                        { "ItemContainerStyle", "{StaticResource itemStyle}" }
                                    },
                                    Children = new List<XamlBuilder>
                                    {
                                        new XamlBuilder<ContentControl>
                                        {
                                            Name = "TemplateContent",
                                            AttributeProperties = new Dictionary<string, string>
                                            {
                                                { "Content", "{Binding Element}" }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        Children = new List<XamlBuilder>
                        {
                            new XamlBuilder<TreeView>
                            {
                                AttributeProperties = new Dictionary<string, string>
                                {
                                    { "ItemTemplate", "{StaticResource template}" },
                                    { "ItemContainerStyle", "{StaticResource itemStyle}" }
                                },
                            }
                        }
                    }
                }
            };

            Grid root = builder.Load();
            TreeView view = null;
            TreeViewItem item = null;

            List<Hierarchy> items = new List<Hierarchy>()
            {
                new Hierarchy { Element = "Brush" },
                new Hierarchy { Element = "Style" },
                new Hierarchy
                {
                    Element = "UIElement",
                    Children = new Collection<Hierarchy>
                    {
                        new Hierarchy
                        {
                            Element = "FrameworkElement",
                            Children = new Collection<Hierarchy>
                            {
                                new Hierarchy
                                {
                                    Element = "Control",
                                    Children = new Collection<Hierarchy>
                                    {
                                        new Hierarchy { Element = "TextBox" }
                                    }
                                }
                            }
                        }
                    }
                },
                new Hierarchy { Element = "VisualStateManager" }
            };

            TestAsync(
                5,
                root,
                () => view = (root.Children[0] as Grid).Children[0] as TreeView,
                () => view.ItemsSource = items,
                () => item = view.ItemContainerGenerator.ContainerFromIndex(2) as TreeViewItem,
                () => Assert.AreEqual(15.0, item.FontSize, "Style not applied to first item!"),
                () => item.IsExpanded = true,
                () => item = item.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem,
                () => Assert.AreEqual(15.0, item.FontSize, "Style not applied to second item!"),
                () => item.IsExpanded = true,
                () => item = item.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem,
                () => Assert.AreEqual(15.0, item.FontSize, "Style not applied to third item!"),
                () => item.IsExpanded = true);
        }
        public virtual void GetItemsHostIsCorrectPanel()
        {
            string name = "DesiredPanel";
            ItemsControl control = new ItemsControl { ItemsSource = new[] { 1, 2, 3, 4, 5 } };
            Panel host = null;
            XamlBuilder<ItemsPanelTemplate> builder = new XamlBuilder<ItemsPanelTemplate>
            {
                Children = new List<XamlBuilder>
                {
                    new XamlBuilder<StackPanel> { Name = name }
                }
            };
            control.ItemsPanel = builder.Load();

            TestAsync(
                control,
                () => host = control.GetItemsHost(),
                () => Assert.IsNotNull(host, "Failed to find ItemsHost!"),
                () => Assert.AreEqual(name, host.Name, "ItemsHost name did not match!"));
        }
        public virtual void GetScrollHostWithNoItemsHost()
        {
            ListBox control = new ListBox { ItemsSource = new[] { 1, 2, 3, 4, 5 } };
            XamlBuilder<ControlTemplate> builder = new XamlBuilder<ControlTemplate>
            {
                AttributeProperties = new Dictionary<string, string> { { "TargetType", "ListBox" } },
                Children = new List<XamlBuilder> { new XamlBuilder<TextBlock>() }
            };
            control.Template = builder.Load();
            ScrollViewer host = null;

            TestAsync(
                control,
                () => host = control.GetScrollHost(),
                () => Assert.IsNull(host, "Should not have found ScrollHost!"));
        }
        public static HierarchicalDataTemplate GetDataTemplate()
        {
            string templateKey = "template";

            // Wrap the template in a Grid because the XAML parser doesn't like
            // namespaces declared on a DataTemplate
            XamlBuilder <Grid> builder = new XamlBuilder <Grid>
            {
                ExplicitNamespaces = new Dictionary <string, string>
                {
                    { "common", XamlBuilder.GetNamespace(typeof(HierarchicalDataTemplate)) },
                    { "local", XamlBuilder.GetNamespace(typeof(FactorizationValueConverter)) }
                },
                ElementProperties = new Dictionary <string, XamlBuilder>
                {
                    {
                        "Resources",
                        new XamlBuilder <FactorizationValueConverter>
                        {
                            Key = "Factorization"
                        }
                    }
                },
                Children = new List <XamlBuilder>
                {
                    new XamlBuilder <Grid>
                    {
                        ElementProperties = new Dictionary <string, XamlBuilder>
                        {
                            {
                                "Resources",
                                new XamlBuilder <HierarchicalDataTemplate>
                                {
                                    Key = templateKey,
                                    AttributeProperties = new Dictionary <string, string>
                                    {
                                        { "ItemsSource", "{Binding Converter={StaticResource Factorization}}" }
                                    },
                                    Children = new List <XamlBuilder>
                                    {
                                        new XamlBuilder <ContentControl>
                                        {
                                            Name = "TemplateContent",
                                            AttributeProperties = new Dictionary <string, string>
                                            {
                                                { "Content", "{Binding}" }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            Grid outer = builder.Load();
            Grid inner = outer.Children[0] as Grid;

            return(inner.Resources[templateKey] as HierarchicalDataTemplate);
        }
        public static HierarchicalDataTemplate GetDataTemplate()
        {
            string templateKey = "template";

            // Wrap the template in a Grid because the XAML parser doesn't like
            // namespaces declared on a DataTemplate
            XamlBuilder<Grid> builder = new XamlBuilder<Grid>
            {
                ExplicitNamespaces = new Dictionary<string, string>
                {
                    { "common", XamlBuilder.GetNamespace(typeof(HierarchicalDataTemplate)) },
                    { "local", XamlBuilder.GetNamespace(typeof(FactorizationValueConverter)) }
                },
                ElementProperties = new Dictionary<string, XamlBuilder>
                {
                    {
                        "Resources",
                        new XamlBuilder<FactorizationValueConverter>
                        {
                            Key = "Factorization"
                        }
                    }
                },
                Children = new List<XamlBuilder>
                {
                    new XamlBuilder<Grid>
                    {
                        ElementProperties = new Dictionary<string, XamlBuilder>
                        {
                            {
                                "Resources",
                                new XamlBuilder<HierarchicalDataTemplate>
                                {
                                    Key = templateKey,
                                    AttributeProperties = new Dictionary<string, string>
                                    {
                                        { "ItemsSource", "{Binding Converter={StaticResource Factorization}}" }
                                    },
                                    Children = new List<XamlBuilder>
                                    {
                                        new XamlBuilder<ContentControl>
                                        {
                                            Name = "TemplateContent",
                                            AttributeProperties = new Dictionary<string, string>
                                            {
                                                { "Content", "{Binding}" }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }                
            };
            
            Grid outer = builder.Load();
            Grid inner = outer.Children[0] as Grid;
            return inner.Resources[templateKey] as HierarchicalDataTemplate;
        }
        public virtual void ApplyHierarchicalDataTemplateThenSetStyle()
        {
            XamlBuilder<Grid> builder = new XamlBuilder<Grid>
            {
                ExplicitNamespaces = new Dictionary<string, string>
                {
                    { "common", XamlBuilder.GetNamespace(typeof(HierarchicalDataTemplate)) },
                    { "ctl", XamlBuilder.GetNamespace(typeof(TreeViewItem)) },
                    { "sys", XamlBuilder.GetNamespace(typeof(int)) }
                },
                ElementProperties = new Dictionary<string, XamlBuilder>
                {
                    {
                        "Resources",
                        new XamlBuilder<HierarchicalDataTemplate>
                        {
                            Key = "template",
                            AttributeProperties = new Dictionary<string, string> { { "ItemsSource", "{Binding Children}" } },
                            Children = new List<XamlBuilder>
                            {
                                new XamlBuilder<ContentControl>
                                {
                                    Name = "TemplateContent",
                                    AttributeProperties = new Dictionary<string, string>
                                    {
                                        { "Content", "{Binding Element}" }
                                    }
                                }
                            }
                        }
                    }
                },
                Children = new List<XamlBuilder>
                {
                    new XamlBuilder<TreeView>
                    {
                        AttributeProperties = new Dictionary<string, string> { { "ItemTemplate", "{StaticResource template}" } },
                    }
                }
            };

            Grid root = builder.Load();
            TreeView view = null;
            TreeViewItem item = null;

            List<Hierarchy> items = new List<Hierarchy>()
            {
                new Hierarchy { Element = "Brush" },
                new Hierarchy { Element = "Style" },
                new Hierarchy
                {
                    Element = "UIElement",
                    Children = new Collection<Hierarchy>
                    {
                        new Hierarchy
                        {
                            Element = "FrameworkElement",
                            Children = new Collection<Hierarchy>
                            {
                                new Hierarchy
                                {
                                    Element = "Control",
                                    Children = new Collection<Hierarchy>
                                    {
                                        new Hierarchy { Element = "TextBox" }
                                    }
                                }
                            }
                        }
                    }
                },
                new Hierarchy { Element = "VisualStateManager" }
            };

            Style outerStyle = new Style(typeof(TreeViewItem));
            outerStyle.Setters.Add(new Setter(TreeViewItem.FontSizeProperty, 20.0));

            Style innerStyle = new Style(typeof(TreeViewItem));
            innerStyle.Setters.Add(new Setter(TreeViewItem.FontSizeProperty, 10.0));

            TestAsync(
                5,
                root,
                () => view = root.Children[0] as TreeView,
                () => view.ItemsSource = items,
                () => item = view.ItemContainerGenerator.ContainerFromIndex(2) as TreeViewItem,
                () => item.IsExpanded = true,
                () => item = item.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem,
                () => item.IsExpanded = true,
                () => view.ItemContainerStyle = outerStyle,
                () => item = item.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem,
                () => item.IsExpanded = true,
                () => item.ItemContainerStyle = innerStyle,
                () => item.ItemContainerStyle = null);
        }
        public virtual void ShouldAllowTemplateWithUIElements()
        {
            // this tests adds back the coverage lost by the exclusion of
            // test: Content*DataTemplateWithUIElementsFails (see GetDPTests())
            AccordionItem instance = new AccordionItem();

            instance.Width  = 300;
            instance.Height = 300;

            TestAsync(
                instance,
                () =>
            {
                StackPanel element = new StackPanel();
                element.SetValue(FrameworkElement.NameProperty, "UIElementContent");
                element.Children.Add(new Ellipse
                {
                    Fill   = new SolidColorBrush(Colors.Red),
                    Width  = 20,
                    Height = 20
                });
                element.Children.Add(new TextBlock
                {
                    Text = "UIElement Content"
                });
                element.Children.Add(new Ellipse
                {
                    Fill   = new SolidColorBrush(Colors.Blue),
                    Width  = 20,
                    Height = 20
                });
                instance.SetValue(ContentControl.ContentProperty, element);
            },
                () => instance.IsSelected = true,
                () =>
            {
                // Create the DataTemplate
                XamlBuilder <DataTemplate> xamlTemplate = new XamlBuilder <DataTemplate>
                {
                    Name     = "template",
                    Children = new List <XamlBuilder>
                    {
                        new XamlBuilder <StackPanel>
                        {
                            Children = new List <XamlBuilder>
                            {
                                new XamlBuilder <StackPanel>
                                {
                                    AttributeProperties = new Dictionary <string, string> {
                                        { "Orientation", "Horizontal" }
                                    },
                                    Children = new List <XamlBuilder>
                                    {
                                        new XamlBuilder <TextBlock>
                                        {
                                            AttributeProperties = new Dictionary <string, string> {
                                                { "Text", "{}{Binding Name}:  " }
                                            }
                                        },
                                        new XamlBuilder <TextBlock>
                                        {
                                            Name = "nameBinding",
                                            AttributeProperties = new Dictionary <string, string> {
                                                { "Text", "{Binding Name}" }
                                            }
                                        }
                                    }
                                },
                                new XamlBuilder <StackPanel>
                                {
                                    AttributeProperties = new Dictionary <string, string> {
                                        { "Orientation", "Horizontal" }
                                    },
                                    Children = new List <XamlBuilder>
                                    {
                                        new XamlBuilder <TextBlock>
                                        {
                                            AttributeProperties = new Dictionary <string, string> {
                                                { "Text", "{}{Binding}:  " }
                                            }
                                        },
                                        new XamlBuilder <ContentControl>
                                        {
                                            Name = "contentBinding",
                                            AttributeProperties = new Dictionary <string, string> {
                                                { "Content", "{Binding}" }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                // Generate the DataTemplate and set it
                instance.SetValue(ContentControl.ContentTemplateProperty, xamlTemplate.Load());
            },
                () =>
            {
                // Verify the bindings didn't work
                TextBlock text = instance.GetVisualChild("nameBinding") as TextBlock;
                Assert.IsNotNull(text, "Failed to find nameBinding TextBlock!");
                TestExtensions.AssertIsNullOrEmpty(text.Text);

                ContentControl content = instance.GetVisualChild("contentBinding") as ContentControl;
                Assert.IsNotNull(content, "Failed to find contentBinding ContentControl!");
                Assert.IsNull(content.Content, "The bound Content should be null!");
            });
        }
Пример #16
0
        public static HierarchicalDataTemplate GetDataTemplate()
        {
            string templateKey = "template";

            // Wrap the template in a Grid because the XAML parser doesn't like
            // namespaces declared on a DataTemplate
            XamlBuilder<Grid> builder = new XamlBuilder<Grid>
            {
                ExplicitNamespaces = new Dictionary<string, string>
                {
                    { "common", XamlBuilder.GetNamespace(typeof(HierarchicalDataTemplate)) },
                    { "ctl", XamlBuilder.GetNamespace(typeof(TreeViewItem)) },
                    { "sys", XamlBuilder.GetNamespace(typeof(int)) }
                },
                ElementProperties = new Dictionary<string, XamlBuilder>
                {
                    {
                        "Resources",
                        new XamlBuilder<HierarchicalDataTemplate>
                        {
                            Key = templateKey,
                            AttributeProperties = new Dictionary<string, string>
                            {
                                { "ItemsSource", "{Binding Children}" }
                            },
                            Children = new List<XamlBuilder>
                            {
                                new XamlBuilder<ContentControl>
                                {
                                    Name = "TemplateContent",
                                    AttributeProperties = new Dictionary<string, string>
                                    {
                                        { "Content", "{Binding Element}" },
                                        { "Foreground", "Red" }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            Grid container = builder.Load();
            return container.Resources[templateKey] as HierarchicalDataTemplate;
        }
        public virtual void ApplyHierarchicalDataTemplate()
        {
            XamlBuilder<Grid> builder = new XamlBuilder<Grid>
            {
                ExplicitNamespaces = new Dictionary<string, string>
                {
                    { "common", XamlBuilder.GetNamespace(typeof(HierarchicalDataTemplate)) },
                    { "ctl", XamlBuilder.GetNamespace(typeof(TreeViewItem)) },
                    { "sys", XamlBuilder.GetNamespace(typeof(int)) }
                },
                ElementProperties = new Dictionary<string, XamlBuilder>
                {
                    {
                        "Resources",
                        new XamlBuilder<HierarchicalDataTemplate>
                        {
                            Key = "template",
                            AttributeProperties = new Dictionary<string, string> { { "ItemsSource", "{Binding Children}" } },
                            Children = new List<XamlBuilder>
                            {
                                new XamlBuilder<ContentControl>
                                {
                                    Name = "TemplateContent",
                                    AttributeProperties = new Dictionary<string, string>
                                    {
                                        { "Content", "{Binding Element}" },
                                        { "Foreground", "Red" }
                                    }
                                }
                            }
                        }
                    }
                },
                Children = new List<XamlBuilder>
                {
                    new XamlBuilder<TreeView>
                    {
                        AttributeProperties = new Dictionary<string, string> { { "ItemTemplate", "{StaticResource template}" } },
                    }
                }
            };

            Grid root = builder.Load();
            TreeView view = null;
            TreeViewItem item = null;
            Hierarchy textbox = null;

            List<Hierarchy> items = new List<Hierarchy>()
            {
                new Hierarchy { Element = "Brush" },
                new Hierarchy { Element = "Style" },
                new Hierarchy
                {
                    Element = "UIElement",
                    Children = new Collection<Hierarchy>
                    {
                        new Hierarchy
                        {
                            Element = "FrameworkElement",
                            Children = new Collection<Hierarchy>
                            {
                                new Hierarchy
                                {
                                    Element = "Control",
                                    Children = new Collection<Hierarchy>
                                    {
                                        new Hierarchy { Element = "TextBox" }
                                    }
                                }
                            }
                        }
                    }
                },
                new Hierarchy { Element = "VisualStateManager" }
            };

            TestAsync(
                5,
                root,
                () => view = root.Children[0] as TreeView,
                () => view.ItemsSource = items,
                () => item = view.ItemContainerGenerator.ContainerFromIndex(2) as TreeViewItem,
                () => item.IsExpanded = true,
                () => item = item.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem,
                () => item.IsExpanded = true,
                () => item = item.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem,
                () => item.IsExpanded = true,
                () => item = item.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem,
                () => textbox = item.Header as Hierarchy,
                () => Assert.IsNotNull(textbox, "TextBox reference should not be null!"),
                () => Assert.AreEqual("TextBox", textbox.Element, "Unexpected Element!"));
        }
        public virtual void ApplyItemTemplate()
        {
            XamlBuilder<Grid> builder = new XamlBuilder<Grid>
            {
                ExplicitNamespaces = new Dictionary<string, string>
                {
                    { "toolkit", XamlBuilder.GetNamespace(typeof(ObjectCollection)) },
                    { "ctl", XamlBuilder.GetNamespace(typeof(System.Windows.Controls.TreeView)) },
                    { "sys", XamlBuilder.GetNamespace(typeof(int)) },
                },
                ElementProperties = new Dictionary<string, XamlBuilder>
                {
                    {
                        "Resources",
                        new XamlBuilder<DataTemplate>
                        {
                            Key = "template",
                            Children = new List<XamlBuilder>
                            {
                                new XamlBuilder<ContentControl>
                                {
                                    Name = "TemplateContent",
                                    AttributeProperties = new Dictionary<string, string>
                                    {
                                        { "Content", "{Binding}" },
                                        { "Foreground", "Red" }
                                    }
                                }
                            }
                        }
                    }
                },
                Children = new List<XamlBuilder>
                {
                    new XamlBuilder<TreeView>
                    {
                        AttributeProperties = new Dictionary<string, string> { { "ItemTemplate", "{StaticResource template}" } },
                        ElementProperties = new Dictionary<string, XamlBuilder>
                        {
                            {
                                "ItemsSource",
                                new XamlBuilder<ObjectCollection>
                                {
                                    Children = new List<XamlBuilder>
                                    {
                                        new XamlBuilder<int> { Content = "1" },
                                        new XamlBuilder<int> { Content = "2" },
                                        new XamlBuilder<int> { Content = "3" }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            Grid root = builder.Load();
            TreeView view = null;
            TreeViewItem first = null;
            ContentControl header = null;

            TestAsync(
                5,
                root,
                () => view = root.Children[0] as TreeView,
                () => first = view.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem,
                () => Assert.IsNotNull(first, "First item should not be null!"),
                () => Assert.AreEqual(1, first.Header, "Unexpected header!"),
                () => header = first.GetVisualChild("TemplateContent") as ContentControl,
                () => Assert.IsNotNull(header, "Header should not be null!"));
        }
        public virtual void ScrollIntoViewNoScrollHost()
        {
            TreeView view = new TreeView();
            TreeViewItem first = new TreeViewItem { Header = "First" };
            TreeViewItem second = new TreeViewItem { Header = 2 };
            view.Items.Add(first);
            view.Items.Add(second);

            TreeViewAutomationPeer viewPeer = null;
            TreeViewItemAutomationPeer firstPeer = null;
            IScrollItemProvider firstProvider = null;
            TreeViewItemAutomationPeer secondPeer = null;
            IScrollItemProvider secondProvider = null;

            // Create a template without a ScrollViewer
            XamlBuilder<ControlTemplate> builder = new XamlBuilder<ControlTemplate>
            {
                ExplicitNamespaces = new Dictionary<string, string> { { "ctls", XamlBuilder.GetNamespace(typeof(TreeView)) } },
                AttributeProperties = new Dictionary<string, string> { { "TargetType", "ctls:TreeView" } },
                Children = new List<XamlBuilder> { new XamlBuilder<ItemsPresenter>() }
            };
            view.Template = builder.Load();

            TestAsync(
                view,
                () => viewPeer = FrameworkElementAutomationPeer.CreatePeerForElement(view) as TreeViewAutomationPeer,
                () => firstPeer = FrameworkElementAutomationPeer.CreatePeerForElement(first) as TreeViewItemAutomationPeer,
                () => secondPeer = FrameworkElementAutomationPeer.CreatePeerForElement(second) as TreeViewItemAutomationPeer,
                () => firstProvider = firstPeer.GetPattern(PatternInterface.ScrollItem) as IScrollItemProvider,
                () => secondProvider = secondPeer.GetPattern(PatternInterface.ScrollItem) as IScrollItemProvider,
                () => firstProvider.ScrollIntoView());
        }
        public virtual void ShouldAllowTemplateWithUIElements()
        {
            // this tests adds back the coverage lost by the exclusion of
            // test: Content*DataTemplateWithUIElementsFails (see GetDPTests())
            AccordionItem instance = new AccordionItem();
            instance.Width = 300;
            instance.Height = 300;

            TestAsync(
                    instance,
                    () =>
                        {
                            StackPanel element = new StackPanel();
                            element.SetValue(FrameworkElement.NameProperty, "UIElementContent");
                            element.Children.Add(new Ellipse
                                                     {
                                                             Fill = new SolidColorBrush(Colors.Red),
                                                             Width = 20,
                                                             Height = 20
                                                     });
                            element.Children.Add(new TextBlock
                                                     {
                                                             Text = "UIElement Content"
                                                     });
                            element.Children.Add(new Ellipse
                                                     {
                                                             Fill = new SolidColorBrush(Colors.Blue),
                                                             Width = 20,
                                                             Height = 20
                                                     });
                            instance.SetValue(ContentControl.ContentProperty, element);
                        },
                    () => instance.IsSelected = true,
                () =>
                {
                    // Create the DataTemplate
                    XamlBuilder<DataTemplate> xamlTemplate = new XamlBuilder<DataTemplate>
                    {
                        Name = "template",
                        Children = new List<XamlBuilder>
                        {
                            new XamlBuilder<StackPanel>
                            {
                                Children = new List<XamlBuilder>
                                {
                                    new XamlBuilder<StackPanel>
                                    {
                                        AttributeProperties = new Dictionary<string, string> { { "Orientation", "Horizontal" } },
                                        Children = new List<XamlBuilder>
                                        {
                                            new XamlBuilder<TextBlock>
                                            {
                                                AttributeProperties = new Dictionary<string, string> { { "Text", "{}{Binding Name}:  " } }
                                            },
                                            new XamlBuilder<TextBlock>
                                            {
                                                Name = "nameBinding",
                                                AttributeProperties = new Dictionary<string, string> { { "Text", "{Binding Name}" } }
                                            }
                                        }
                                    },
                                    new XamlBuilder<StackPanel>
                                    {
                                        AttributeProperties = new Dictionary<string, string> { { "Orientation", "Horizontal" } },
                                        Children = new List<XamlBuilder>
                                        {
                                            new XamlBuilder<TextBlock>
                                            {
                                                AttributeProperties = new Dictionary<string, string> { { "Text", "{}{Binding}:  " } }
                                            },
                                            new XamlBuilder<ContentControl>
                                            {
                                                Name = "contentBinding",
                                                AttributeProperties = new Dictionary<string, string> { { "Content", "{Binding}" } }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    };

                    // Generate the DataTemplate and set it
                    instance.SetValue(ContentControl.ContentTemplateProperty, xamlTemplate.Load());
                },
                () =>
                {
                    // Verify the bindings didn't work
                    TextBlock text = instance.GetVisualChild("nameBinding") as TextBlock;
                    Assert.IsNotNull(text, "Failed to find nameBinding TextBlock!");
                    TestExtensions.AssertIsNullOrEmpty(text.Text);

                    ContentControl content = instance.GetVisualChild("contentBinding") as ContentControl;
                    Assert.IsNotNull(content, "Failed to find contentBinding ContentControl!");
                    Assert.IsNull(content.Content, "The bound Content should be null!");
                });
        }
        public virtual void ApplyHierarchicalDataTemplateWithItemTemplate()
        {
            XamlBuilder<Grid> builder = new XamlBuilder<Grid>
            {
                ExplicitNamespaces = new Dictionary<string, string>
                {
                    { "common", XamlBuilder.GetNamespace(typeof(HierarchicalDataTemplate)) },
                    { "ctl", XamlBuilder.GetNamespace(typeof(TreeViewItem)) },
                    { "sys", XamlBuilder.GetNamespace(typeof(int)) }
                },
                ElementProperties = new Dictionary<string, XamlBuilder>
                {
                    {
                        "Resources",
                        new XamlBuilder<DataTemplate>
                        {
                            Key = "itemTemplate",
                            Children = new List<XamlBuilder>
                            {
                                new XamlBuilder<ContentControl>
                                {
                                    Name = "TemplateContent",
                                    AttributeProperties = new Dictionary<string, string>
                                    {
                                        { "Content", "{Binding Element}" },
                                        { "FontWeight", "Bold" }
                                    }
                                }
                            }
                        }
                    }
                },
                Children = new List<XamlBuilder>
                {
                    new XamlBuilder<Grid>
                    {
                        ElementProperties = new Dictionary<string, XamlBuilder>
                        {
                            {
                                "Resources",
                                new XamlBuilder<HierarchicalDataTemplate>
                                {
                                    Key = "template",
                                    AttributeProperties = new Dictionary<string, string>
                                    {
                                        { "ItemsSource", "{Binding Children}" },
                                        { "ItemTemplate", "{StaticResource itemTemplate}" }
                                    },
                                    Children = new List<XamlBuilder>
                                    {
                                        new XamlBuilder<ContentControl>
                                        {
                                            Name = "TemplateContent",
                                            AttributeProperties = new Dictionary<string, string>
                                            {
                                                { "Content", "{Binding Element}" },
                                                { "FontStyle", "Italic" }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        Children = new List<XamlBuilder>
                        {
                            new XamlBuilder<TreeView>
                            {
                                AttributeProperties = new Dictionary<string, string>
                                {
                                    { "ItemTemplate", "{StaticResource template}" }
                                },
                            }
                        }
                    }
                }
            };

            Grid root = builder.Load();
            TreeView view = null;
            TreeViewItem item = null;

            List<Hierarchy> items = new List<Hierarchy>()
            {
                new Hierarchy { Element = "Brush" },
                new Hierarchy { Element = "Style" },
                new Hierarchy
                {
                    Element = "UIElement",
                    Children = new Collection<Hierarchy>
                    {
                        new Hierarchy
                        {
                            Element = "FrameworkElement",
                            Children = new Collection<Hierarchy>
                            {
                                new Hierarchy
                                {
                                    Element = "Control",
                                    Children = new Collection<Hierarchy>
                                    {
                                        new Hierarchy { Element = "TextBox" }
                                    }
                                }
                            }
                        }
                    }
                },
                new Hierarchy { Element = "VisualStateManager" }
            };

            TestAsync(
                5,
                root,
                () => view = (root.Children[0] as Grid).Children[0] as TreeView,
                () => view.ItemsSource = items,
                () => item = view.ItemContainerGenerator.ContainerFromIndex(2) as TreeViewItem,
                () => item.IsExpanded = true,
                () => item = item.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem,
                () => Assert.AreEqual(0, item.Items.Count, "Only the first level should have nested items!"));
        }