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();
     }
 }
        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 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);
        }