void ClassBindingTest2() { var fe = new FrameworkElement(); var template = Template.CreateFromXml(@"<div class='{Class}' />"); UIBuilder.BuildControlTemplate(template, fe); MustEqual(null, fe.Attr("class")); fe.Class = "b"; MustEqual("b", fe.Attr("class")); }
internal static void DefineForBuilder() { var template = Template.CreateFromXml("<div class='{StringProperty0}' >" + " <div class='{StringProperty1}' />" + " <div class='{StringProperty2}' x.Name = '_propValue2' />" + " <div class='{StringProperty1}' />" + "</div>"); UIBuilder.Register("Component123", () => { var fe = new Component123(); UIBuilder.BuildControlTemplate(template, fe); if (fe._propValue2 == null) { throw new InvalidOperationException(); } return(fe); }); }
void Template_creation() { var fe = new TestElement { StringProperty0 = "A", StringProperty1 = "B" }; var template = Template.CreateFromXml("<div class='{StringProperty0}'> " + " <div Visibility='{LabelVisbility}'> " + " <div x='{StringProperty1}' /> " + " </div> " + "</div>"); UIBuilder.BuildControlTemplate(template, fe); AssertNotNull(fe._root); MustEqual("A", fe.Attr("class")); MustEqual("B", fe.GetVisualChildAt(0, 0, 0).Attr("x")); MustTrue(fe.GetVisualChildAt(0, 0).Visibility == System.Windows.Visibility.Collapsed); }
void VisualTreeTest_TemplateControl() { var model = new SimpleClass1 { LastName = "X", Child = new SimpleClass1 { LastName = "Y", Child = new SimpleClass1 { LastName = "Z" } } }; var xml = "<div class='A' >" + " <div class='B' />" + " <div class='C' />" + " <div class='D' />" + "</div>"; var template = Template.CreateFromXml(xml); UIBuilder.Register("x_r_t_t_6", () => { var fe = new HtmlElement(); UIBuilder.BuildControlTemplate(template, fe); MustEqual(1, fe.VisualChilderenCount); MustEqual(3, fe.GetVisualChildAt(0).VisualChilderenCount); MustEqual("B", fe.GetVisualChildAt(0, 0).Attr("class")); MustEqual("C", fe.GetVisualChildAt(0, 1).Attr("class")); MustEqual("D", fe.GetVisualChildAt(0, 2).Attr("class")); return(fe); }); var containerElement = new HtmlElement { DataContext = model }; UIBuilder.LoadComponent(containerElement, "<x_r_t_t_6> " + " <s class='sf'/>" + "</x_r_t_t_6>"); var containerElementAsHtmlString = containerElement._el.AsHtmlString(); MustEqual( "<div>" + "<div class='A'>" + "<div class='B'></div>" + "<div class='C'></div>" + "<div class='D'></div>" + "<s class='sf'></s>" + "</div>" + "</div>" , containerElementAsHtmlString); containerElement = new HtmlElement { DataContext = model }; UIBuilder.LoadComponent(containerElement, "<div>" + " <div> " + " <x_r_t_t_6> " + " <s class='sf'/> " + " </x_r_t_t_6> " + " </div>" + "</div>"); containerElementAsHtmlString = containerElement._el.AsHtmlString(); MustEqual( "<div>" + "<div>" + "<div>" + "<div class='A'>" + "<div class='B'></div>" + "<div class='C'></div>" + "<div class='D'></div>" + "<s class='sf'></s>" + "</div>" + "</div>" + "</div>" + "</div>" , containerElementAsHtmlString); }