public void BindingExtensionRelativeSourceTemplatedParentTest() { string text = @" <ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='root'> <FrameworkElement x:Name='child' Width='{Binding Height, RelativeSource={RelativeSource TemplatedParent}}'/> </ControlTemplate>"; ControlTemplate template = XamlLoader.Load(XamlParser.Parse(text)) as ControlTemplate; Control control = new Control(); control.Template = template; control.ApplyTemplate(); FrameworkElement child = NameScope.GetTemplateNameScope(control).FindName("child") as FrameworkElement; Assert.AreEqual(control, child.TemplatedParent); control.Height = 100; Assert.AreEqual(100, child.Width); control.ClearValue(FrameworkElement.HeightProperty); child.SetValue(FrameworkElement.WidthProperty, 200.0, BaseValueSource.ParentTemplate); Assert.AreEqual(200, control.Height); }
void SetUpWithCode(string code, int offset) { textEditor.Document.Text = code; textEditor.Caret.Offset = offset; var parseInfo = textEditor.CreateParseInformation(); IProject project = MockRepository.GenerateStrictMock <IProject>(); var pc = new CSharpProjectContent().AddOrUpdateFiles(parseInfo.UnresolvedFile); pc = pc.AddAssemblyReferences(new[] { Corlib, PresentationCore, PresentationFramework, SystemXaml }); var compilation = pc.CreateCompilation(); SD.Services.AddService(typeof(IParserService), MockRepository.GenerateStrictMock <IParserService>()); SD.ParserService.Stub(p => p.GetCachedParseInformation(textEditor.FileName)).Return(parseInfo); SD.ParserService.Stub(p => p.GetCompilation(project)).Return(compilation); SD.ParserService.Stub(p => p.GetCompilationForFile(textEditor.FileName)).Return(compilation); SD.ParserService.Stub(p => p.Parse(textEditor.FileName, textEditor.Document)).WhenCalled( i => { var p = new XamlParser(); p.TaskListTokens = TaskListTokens; i.ReturnValue = p.Parse(textEditor.FileName, textEditor.Document, true, project, CancellationToken.None); }).Return(parseInfo); // fake Return to make it work SD.Services.AddService(typeof(IFileService), MockRepository.GenerateStrictMock <IFileService>()); IViewContent view = MockRepository.GenerateStrictMock <IViewContent>(); view.Stub(v => v.GetService(typeof(ITextEditor))).Return(textEditor); SD.FileService.Stub(f => f.OpenFile(textEditor.FileName, false)).Return(view); }
public void DockPanelLayoutParseTest() { string text = @" <DockPanel xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <FrameworkElement Width='100' DockPanel.Dock='Left'/> <FrameworkElement Height='100' DockPanel.Dock='Top'/> <FrameworkElement Width='100' DockPanel.Dock='Right'/> <FrameworkElement Height='100' DockPanel.Dock='Bottom'/> <FrameworkElement/> </DockPanel>"; XamlElement rootElement = XamlParser.Parse(text); DockPanel panel = XamlLoader.Load(rootElement) as DockPanel; panel.Measure(new Size(1000, 1000)); Assert.AreEqual(new Size(200, 200), panel.DesiredSize); panel.Arrange(new Rect(1000, 1000)); Assert.AreEqual(new Size(1000, 1000), panel.VisualSize); Assert.AreEqual(new Size(100, 1000), panel.Children[0].VisualSize); Assert.AreEqual(new Size(900, 100), panel.Children[1].VisualSize); Assert.AreEqual(new Size(100, 900), panel.Children[2].VisualSize); Assert.AreEqual(new Size(800, 100), panel.Children[3].VisualSize); Assert.AreEqual(new Size(800, 800), panel.Children[4].VisualSize); Assert.AreEqual(new Point(0, 0), panel.Children[0].VisualOffset); Assert.AreEqual(new Point(100, 0), panel.Children[1].VisualOffset); Assert.AreEqual(new Point(900, 100), panel.Children[2].VisualOffset); Assert.AreEqual(new Point(100, 900), panel.Children[3].VisualOffset); Assert.AreEqual(new Point(100, 100), panel.Children[4].VisualOffset); }
public void TemplatedParentSourceObserverTest() { string text = @" <ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <FrameworkElement x:Name='child'/> </ControlTemplate>"; ControlTemplate template = XamlLoader.Load(XamlParser.Parse(text)) as ControlTemplate; Control control = new Control(); control.Template = template; control.ApplyTemplate(); FrameworkElement child = NameScope.GetTemplateNameScope(control).FindName("child") as FrameworkElement; Freezable value = new Freezable(); TemplatedParentSourceObserver observer = new TemplatedParentSourceObserver(value); Assert.AreEqual(ObservableValue.UnsetValue, observer.Value); child.SetValue(ValueProperty, value); Assert.AreEqual(control, observer.Value); child.SetValue(ValueProperty, null); Assert.AreEqual(ObservableValue.UnsetValue, observer.Value); }
void SetUpWithCode(string code, int offset) { textEditor.Document.Text = code; textEditor.Caret.Offset = offset; var parseInfo = textEditor.CreateParseInformation(); IProject project = MockRepository.GenerateStrictMock<IProject>(); var pc = new CSharpProjectContent().AddOrUpdateFiles(parseInfo.UnresolvedFile); pc = pc.AddAssemblyReferences(new[] { Corlib, PresentationCore, PresentationFramework, SystemXaml }); var compilation = pc.CreateCompilation(); SD.Services.AddService(typeof(IParserService), MockRepository.GenerateStrictMock<IParserService>()); SD.ParserService.Stub(p => p.GetCachedParseInformation(textEditor.FileName)).Return(parseInfo); SD.ParserService.Stub(p => p.GetCompilation(project)).Return(compilation); SD.ParserService.Stub(p => p.GetCompilationForFile(textEditor.FileName)).Return(compilation); SD.ParserService.Stub(p => p.Parse(textEditor.FileName, textEditor.Document)).WhenCalled( i => { var p = new XamlParser(); p.TaskListTokens = TaskListTokens; i.ReturnValue = p.Parse(textEditor.FileName, textEditor.Document, true, project, CancellationToken.None); }).Return(parseInfo); // fake Return to make it work SD.Services.AddService(typeof(IFileService), MockRepository.GenerateStrictMock<IFileService>()); IViewContent view = MockRepository.GenerateStrictMock<IViewContent>(); view.Stub(v => v.GetService(typeof(ITextEditor))).Return(textEditor); SD.FileService.Stub(f => f.OpenFile(textEditor.FileName, false)).Return(view); }
public void NamescopeTest1() { var xaml = @" <UserControl xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation"" xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @""" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" x:Name=""root"" > <Grid x:Name=""rootGrid"" > <Button x:Name=""aa"" /> <Button x:Name=""bb"" /> <t:ExampleControl Property1=""{x:Reference aa}"" /> </Grid> </UserControl>"; var obj = XamlParser.Parse(new StringReader(xaml)); ((FrameworkElement)obj.RootInstance).CreateVisualTree(); var example = ((FrameworkElement)obj.RootInstance).TryFindChild <ExampleControl>(); var buttonAa = ((FrameworkElement)obj.RootInstance).TryFindChild <Button>("aa"); Assert.AreEqual(example.Property1, buttonAa); }
public void CompileText() { try { if (mainViewModel.TextContent.IsNullOrWhiteSpace()) { contentPresenter.Child = null; } else { FrameworkElement child = (FrameworkElement)XamlLoader.Load(XamlParser.Parse(mainViewModel.TextContent, new Uri("pack://application:,,,/GranularPad;component/"))); child.DataContext = null; contentPresenter.Child = child; } HideErrorMessage(); HideContentPresenterOverlay(); } catch (Exception e) { errorTextBlock.Text = e.Message; errorPosition = ParseErrorPosition(e.Message); ShowErrorMessage(); ShowContentPresenterOverlay(); } }
public string Convert(string workflowXaml) { XamlDocument document = xamlParser.Parse(workflowXaml); ClassCode classCode = classGenerator.Generate(document); return(classCodeToCSharp.Convert(classCode)); }
public void XamlLoadKeyElementTest() { string text = @" <ResourceDictionary xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'> <test:LoaderTestElement Value1='1' Value2='2'> <x:Key> <test:LoaderTestElement Value1='3' Value2='4'/> </x:Key> </test:LoaderTestElement> </ResourceDictionary>"; XamlElement rootElement = XamlParser.Parse(text); ResourceDictionary dictionary = XamlLoader.Load(rootElement) as ResourceDictionary; Assert.IsNotNull(dictionary); Assert.AreEqual(1, dictionary.Count); LoaderTestElement key = (LoaderTestElement)dictionary.Keys.First(); LoaderTestElement value = (LoaderTestElement)dictionary[key]; Assert.AreEqual(1, value.Value1); Assert.AreEqual(2, value.Value2); Assert.AreEqual(3, key.Value1); Assert.AreEqual(4, key.Value2); }
public void XamlLoadEventsTest() { string text = @" <test:LoaderTestElement xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'> <test:LoaderTestElement x:Name='element1' Action1='Handler1' Action2='Handler2'/> <test:LoaderTestElement x:Name='element2' test:LoaderTestElement.Action1='Handler3' test:LoaderTestElement.Action2='Handler4'/> </test:LoaderTestElement>"; LoaderTestTopElement root = new LoaderTestTopElement(); XamlLoader.Load(root, XamlParser.Parse(text)); LoaderTestElement element1 = NameScope.GetNameScope(root).FindName("element1") as LoaderTestElement; LoaderTestElement element2 = NameScope.GetNameScope(root).FindName("element2") as LoaderTestElement; element1.RaiseAction1(); element1.RaiseAction2(); element2.RaiseAction1(); element2.RaiseAction1(); element2.RaiseAction2(); element2.RaiseAction2(); Assert.IsTrue(root != null); Assert.AreEqual(1, root.Handler1Calls); //Assert.AreEqual(1, root.Handler2Calls); Assert.AreEqual(2, root.Handler3Calls); //Assert.AreEqual(2, root.Handler4Calls); }
public void XamlLoadCollectionReplacePropertyTest() { string text = @" <test:LoaderTestCollectionElement xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'> <test:LoaderTestCollectionElement.Items> <test:LoaderTestCollection> <test:LoaderTestElement Value1='1'/> <test:LoaderTestElement Value1='2'/> <test:LoaderTestElement Value1='3'/> </test:LoaderTestCollection> </test:LoaderTestCollectionElement.Items> </test:LoaderTestCollectionElement>"; XamlElement rootElement = XamlParser.Parse(text); object root1 = XamlLoader.Load(rootElement); Assert.IsTrue(root1 is LoaderTestCollectionElement); Assert.AreEqual(3, (root1 as LoaderTestCollectionElement).Items.Count); Assert.IsTrue((root1 as LoaderTestCollectionElement).Items[0] is LoaderTestElement); Assert.IsTrue((root1 as LoaderTestCollectionElement).Items[1] is LoaderTestElement); Assert.IsTrue((root1 as LoaderTestCollectionElement).Items[2] is LoaderTestElement); Assert.AreEqual(1, ((root1 as LoaderTestCollectionElement).Items[0] as LoaderTestElement).Value1); Assert.AreEqual(2, ((root1 as LoaderTestCollectionElement).Items[1] as LoaderTestElement).Value1); Assert.AreEqual(3, ((root1 as LoaderTestCollectionElement).Items[2] as LoaderTestElement).Value1); }
private void ExecFileOpen() { // Create OpenFileDialog Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // Set filter for file extension and default file extension dlg.DefaultExt = ".xaml"; dlg.Filter = "XAML Files (*.xaml)|*.xaml|Any files (*.*)|*.*"; dlg.InitialDirectory = Properties.Settings.Default.LastOpenDirectory; // Display OpenFileDialog by calling ShowDialog method bool?result = dlg.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { Properties.Settings.Default.LastOpenDirectory = Path.GetDirectoryName(dlg.FileName); Properties.Settings.Default.Save(); // Open document string fileName = dlg.FileName; XamlParser parser = new XamlParser(new TraceErrorHandler()); XamlMainObjectNode mainObjectNode = parser.Parse(fileName); //Parse01(fileName); //Parse03(fileName); } }
public void StaticResourceExtensionBaseTest() { string text = @" <StackPanel xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests;assembly=Granular.Presentation.Tests' x:Name='panel1'> <StackPanel.Resources> <test:ResourceTestObject x:Key='key1' Value='1'/> <test:ResourceTestObject x:Key='key2' Child='{StaticResource key1}'/> </StackPanel.Resources> <FrameworkElement x:Name='child1' test:ResourceTestObject.TestValue='{StaticResource key1}'/> <FrameworkElement x:Name='child2' test:ResourceTestObject.TestValue='{StaticResource key2}'/> </StackPanel>"; FrameworkElement panel1 = XamlLoader.Load(XamlParser.Parse(text)) as FrameworkElement; FrameworkElement child1 = NameScope.GetNameScope(panel1).FindName("child1") as FrameworkElement; FrameworkElement child2 = NameScope.GetNameScope(panel1).FindName("child2") as FrameworkElement; ResourceTestObject testValue1 = (ResourceTestObject)child1.GetValue(ResourceTestObject.TestValueProperty); ResourceTestObject testValue2 = (ResourceTestObject)child2.GetValue(ResourceTestObject.TestValueProperty); Assert.AreEqual(1, testValue1.Value); Assert.AreEqual(testValue1, testValue2.Child); panel1.Resources.Clear(); Assert.AreEqual(1, testValue1.Value); Assert.AreEqual(testValue1, testValue2.Child); }
public void MarkupCompatibilityNestedIgnoreProperties() { XamlElement root = XamlParser.Parse(@" <root xmlns='namespace' xmlns:n1='namepsace1' xmlns:n2='namepsace2' xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' property='valuevalue' n1:property='value1' n2:property='value2'> <element mc:Ignorable='n1' property='valuevalue' n1:property='value1' n2:property='value2'> <element mc:Ignorable='n2' property='valuevalue' n1:property='value1' n2:property='value2'/> </element> </root>"); Assert.AreEqual(3, root.Members.Count()); Assert.AreEqual(2, ((XamlElement)root.Values.First()).Members.Count()); Assert.AreEqual(1, ((XamlElement)((XamlElement)root.Values.First()).Values.First()).Members.Count()); }
public void ParseTest() { XamlElement root1 = XamlParser.Parse(@" <root1 xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:ns1='namespace1' xmlns:ns2='namespace2' member1='value1' ns2:member2='value2'> <!-- comment --> <ns1:child1/> <child2> value3 <child3> </child3> value4 </child2> </root1>"); Assert.AreEqual("root1", root1.Name.LocalName); Assert.AreEqual(2, root1.Members.Count()); Assert.IsTrue(root1.Members.Any(member => member.Name.Equals(new XamlName("member1", "http://schemas.microsoft.com/winfx/2006/xaml/presentation")) && (string)member.Values.Single() == "value1")); Assert.IsTrue(root1.Members.Any(member => member.Name.Equals(new XamlName("member2", "namespace2")) && (string)member.Values.Single() == "value2")); Assert.AreEqual(2, root1.Values.Count()); Assert.AreEqual("child1", ((XamlElement)root1.Values.First()).Name.LocalName); Assert.AreEqual("namespace1", ((XamlElement)root1.Values.First()).Name.NamespaceName); Assert.AreEqual("value3", ((XamlElement)root1.Values.Last()).Values.ElementAt(0)); Assert.AreEqual("child3", ((XamlElement)((XamlElement)root1.Values.Last()).Values.ElementAt(1)).Name.LocalName); Assert.AreEqual("value4", ((XamlElement)root1.Values.Last()).Values.ElementAt(2)); }
private bool InvokeZenCoding() { Span zenSpan = GetText(); if (zenSpan.Length == 0 || TextView.Selection.SelectedSpans[0].Length > 0 || !IsValidTextBuffer()) { return(false); } string zenSyntax = TextView.TextBuffer.CurrentSnapshot.GetText(zenSpan); string result = XamlParser.Parse(zenSyntax); if (!string.IsNullOrEmpty(result)) { Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { ITextSelection selection = UpdateTextBuffer(zenSpan, result); Span newSpan = new Span(zenSpan.Start, selection.SelectedSpans[0].Length); vsXenPackage.ExecuteCommand("Edit.FormatSelection"); SetCaret(newSpan, false); selection.Clear(); }), DispatcherPriority.ApplicationIdle, null); return(true); } return(false); }
public void XamlClassParserBasicTest() { string text = @" <ContentControl x:Class='Granular.BuildTasks.Tests.TestClass' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.BuildTasks.Tests'> <Control.Background> <SolidColorBrush x:Name='brush1' Color='Red'/> </Control.Background> <ContentControl.Content> <test:TestElement x:Name='content1'> <FrameworkElement x:Name='content2'/> </test:TestElement> </ContentControl.Content> </ContentControl>"; XamlElement root = XamlParser.Parse(text); ClassDefinition classDefinition = XamlClassParser.Parse(root, new TestTypeParser()); MemberDefinition[] expectedMembers = new[] { new MemberDefinition("brush1", "System.Windows.Media.SolidColorBrush"), new MemberDefinition("content1", "Granular.BuildTasks.Tests.TestElement"), new MemberDefinition("content2", "System.Windows.FrameworkElement") }; Assert.AreEqual("System.Windows.Controls.ContentControl", classDefinition.BaseTypeName); Assert.AreEqual("TestClass", classDefinition.Name); Assert.AreEqual("Granular.BuildTasks.Tests", classDefinition.Namespace); CollectionAssert.AreEqual(expectedMembers, classDefinition.Members.ToArray()); }
public void DeferredValueSharedTest() { string text = @" <test:DeferredDictionary xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'> <test:TestDictionaryValue x:Key='key1'/> <test:TestDictionaryValue x:Key='key2' x:Shared='false'/> </test:DeferredDictionary>"; DeferredDictionary dictionary = (DeferredDictionary)XamlLoader.Load(XamlParser.Parse(text)); Assert.IsTrue(dictionary.ContainsKey("key1")); Assert.IsTrue(dictionary.ContainsKey("key2")); ValueProvider valueProvider1 = dictionary["key1"] as ValueProvider; ValueProvider valueProvider2 = dictionary["key2"] as ValueProvider; Assert.IsNotNull(valueProvider1); Assert.IsNotNull(valueProvider2); TestDictionaryValue value1 = valueProvider1.ProvideValue() as TestDictionaryValue; TestDictionaryValue value2 = valueProvider2.ProvideValue() as TestDictionaryValue; Assert.IsNotNull(value1); Assert.IsNotNull(value2); TestDictionaryValue value1a = valueProvider1.ProvideValue() as TestDictionaryValue; TestDictionaryValue value2a = valueProvider2.ProvideValue() as TestDictionaryValue; Assert.IsTrue(ReferenceEquals(value1, value1a)); Assert.IsFalse(ReferenceEquals(value2, value2a)); }
public void CanvasLayoutParseTest() { string text = @" <Canvas xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <FrameworkElement Width='200' Height='100' Canvas.Left='20' Canvas.Top='10'/> <FrameworkElement Width='200' Height='100' Canvas.Right='20' Canvas.Top='10'/> <FrameworkElement Width='200' Height='100' Canvas.Right='20' Canvas.Bottom='10'/> <FrameworkElement Width='200' Height='100' Canvas.Left='20' Canvas.Bottom='10'/> </Canvas>"; XamlElement rootElement = XamlParser.Parse(text); Canvas panel = XamlLoader.Load(rootElement) as Canvas; panel.Measure(new Size(1000, 1000)); Assert.AreEqual(Size.Zero, panel.DesiredSize); panel.Arrange(new Rect(1000, 1000)); Assert.AreEqual(new Size(1000, 1000), panel.VisualSize); Assert.AreEqual(new Size(200, 100), panel.Children[0].VisualSize); Assert.AreEqual(new Size(200, 100), panel.Children[1].VisualSize); Assert.AreEqual(new Size(200, 100), panel.Children[2].VisualSize); Assert.AreEqual(new Size(200, 100), panel.Children[3].VisualSize); Assert.AreEqual(new Point(20, 10), panel.Children[0].VisualOffset); Assert.AreEqual(new Point(780, 10), panel.Children[1].VisualOffset); Assert.AreEqual(new Point(780, 890), panel.Children[2].VisualOffset); Assert.AreEqual(new Point(20, 890), panel.Children[3].VisualOffset); }
public void TemplateAndStyleFindDefaultTest() { Style style = new Style { TargetType = typeof(Control) }; style.Setters.Add(new Setter { Property = new DependencyPropertyPathElement(FrameworkElement.WidthProperty), Value = 100 }); string text = @" <ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' TargetType='{x:Type Control}'> <FrameworkElement/> </ControlTemplate>"; ControlTemplate controlTemplate = XamlLoader.Load(XamlParser.Parse(text)) as ControlTemplate; ResourceDictionary resources = new ResourceDictionary(); resources.Add(new StyleKey(typeof(Control)), style); resources.Add(new TemplateKey(typeof(Control)), controlTemplate); Control control = new Control(); control.Resources = resources; Assert.AreEqual(style, control.Style); Assert.AreEqual(controlTemplate, control.Template); }
public void DynamicResourceExtensionBaseTest() { string text = @" <StackPanel xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests;assembly=Granular.Presentation.Tests' x:Name='panel1'> <StackPanel.Resources> <test:ResourceTestObject x:Key='key1' Value='1'/> </StackPanel.Resources> <FrameworkElement x:Name='child1' test:ResourceTestObject.TestValue='{DynamicResource key1}'/> <StackPanel x:Name='panel2'> <FrameworkElement x:Name='child2' test:ResourceTestObject.TestValue='{DynamicResource key1}'/> </StackPanel> </StackPanel>"; FrameworkElement panel1 = XamlLoader.Load(XamlParser.Parse(text)) as FrameworkElement; FrameworkElement panel2 = NameScope.GetNameScope(panel1).FindName("panel2") as FrameworkElement; FrameworkElement child1 = NameScope.GetNameScope(panel1).FindName("child1") as FrameworkElement; FrameworkElement child2 = NameScope.GetNameScope(panel1).FindName("child2") as FrameworkElement; Assert.AreEqual(1, (child1.GetValue(ResourceTestObject.TestValueProperty) as ResourceTestObject).Value); Assert.AreEqual(1, (child2.GetValue(ResourceTestObject.TestValueProperty) as ResourceTestObject).Value); panel2.Resources = new ResourceDictionary(); panel2.Resources.Add("key1", new ResourceTestObject { Value = 2 }); Assert.AreEqual(1, (child1.GetValue(ResourceTestObject.TestValueProperty) as ResourceTestObject).Value); Assert.AreEqual(2, (child2.GetValue(ResourceTestObject.TestValueProperty) as ResourceTestObject).Value); }
public void StackPanelLayoutParseTest() { string text = @" <StackPanel xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <FrameworkElement Height='100'/> <FrameworkElement Height='100'/> <FrameworkElement Height='100'/> </StackPanel>"; XamlElement rootElement = XamlParser.Parse(text); StackPanel panel = XamlLoader.Load(rootElement) as StackPanel; panel.Measure(new Size(1000, 1000)); Assert.AreEqual(new Size(0, 300), panel.DesiredSize); panel.Arrange(new Rect(1000, 300)); Assert.AreEqual(new Size(1000, 300), panel.VisualSize); Assert.AreEqual(new Size(1000, 100), panel.Children[0].VisualSize); Assert.AreEqual(new Size(1000, 100), panel.Children[1].VisualSize); Assert.AreEqual(new Size(1000, 100), panel.Children[2].VisualSize); Assert.AreEqual(new Point(0, 0), panel.Children[0].VisualOffset); Assert.AreEqual(new Point(0, 100), panel.Children[1].VisualOffset); Assert.AreEqual(new Point(0, 200), panel.Children[2].VisualOffset); }
public void ItemsControlMeasureTest() { string text = @" <ItemsControl xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <ItemsControl.Template> <ControlTemplate> <ItemsPresenter ItemContainerGenerator='{TemplateBinding ItemsControl.ItemContainerGenerator}' Template='{TemplateBinding ItemsControl.ItemsPanel}'/> </ControlTemplate> </ItemsControl.Template> </ItemsControl>"; ItemsControl itemsControl = XamlLoader.Load(XamlParser.Parse(text)) as ItemsControl; itemsControl.Items.Add(new Border { Width = 100, Height = 50 }); itemsControl.Items.Add(new Border { Width = 100, Height = 50 }); itemsControl.Items.Add(new Border { Width = 100, Height = 50 }); itemsControl.Measure(Size.Infinity); Assert.AreEqual(new Size(100, 150), itemsControl.DesiredSize); }
public void XamlLoadContentTest() { string text = "<test:LoaderTestContentElement xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests'>1</test:LoaderTestContentElement>"; object element1 = XamlLoader.Load(XamlParser.Parse(text)); Assert.IsTrue(element1 is LoaderTestContentElement); Assert.AreEqual(1, (element1 as LoaderTestContentElement).Content1); }
public void BindingExtensionRelativeSourceSelfTest() { string text = @"<TextBlock xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Name='textBlock' Text=""{Binding RelativeSource={RelativeSource Self}, Path=Name, StringFormat='Self name is {0}'}""/>"; TextBlock textBlock = XamlLoader.Load(XamlParser.Parse(text)) as TextBlock; Assert.AreEqual("Self name is textBlock", textBlock.Text); }
public void Window1() { var xaml = @"<Window xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" IsActive=""true""> </Window>"; XamlParser.Parse(new StringReader(xaml)); }
public void MarkupCompatibilityIgnoreDeclaringElement() { XamlElement root = XamlParser.Parse(@" <root xmlns='namespace' xmlns:n1='namepsace1' xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006'> <n1:element mc:Ignorable='n1'/> <n1:element /> </root>"); Assert.AreEqual(1, root.Values.Count()); }
public void XamlMarkupExtensionTest() { string text = @"<test:LoaderTestElement xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:test='clr-namespace:Granular.Presentation.Tests.Markup;assembly=Granular.Presentation.Tests' Value3='{test:LoaderTestBinding Path=A.B.C}'/>"; XamlElement rootElement = XamlParser.Parse(text); object root1 = XamlLoader.Load(rootElement); Assert.IsTrue((root1 as LoaderTestElement).Value3 is LoaderTestBindingExpression); Assert.AreEqual("A.B.C", ((root1 as LoaderTestElement).Value3 as LoaderTestBindingExpression).Path); }
public void XamlTypesTest() { object element1 = XamlLoader.Load(XamlParser.Parse("<x:Null xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'/>")); Assert.IsNull(element1); object element2 = XamlLoader.Load(XamlParser.Parse("<x:Type xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:s='clr-namespace:System' Type='s:Double'/>")); Assert.AreEqual(typeof(Double), element2); }
public void ScrollViewerComputedVisibilityTest() { string text = @" <ScrollViewer xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Width='200' Height='100' HorizontalScrollBarVisibility='Auto' VerticalScrollBarVisibility='Auto'> <ScrollViewer.Template> <ControlTemplate TargetType='{x:Type ScrollViewer}'> <ScrollContentPresenter x:Name='PART_ScrollContentPresenter' Content='{TemplateBinding Content}'/> </ControlTemplate> </ScrollViewer.Template> <Border x:Name='border'/> </ScrollViewer>"; ScrollViewer scrollViewer = XamlLoader.Load(XamlParser.Parse(text)) as ScrollViewer; scrollViewer.IsRootElement = true; scrollViewer.Measure(Size.Infinity); scrollViewer.Arrange(new Rect(scrollViewer.DesiredSize)); Border border = NameScope.GetNameScope(scrollViewer).FindName("border") as Border; border.Width = 10; border.Height = 10; Assert.AreEqual(Visibility.Collapsed, scrollViewer.ComputedHorizontalScrollBarVisibility); Assert.AreEqual(Visibility.Collapsed, scrollViewer.ComputedVerticalScrollBarVisibility); Assert.AreEqual(border.Width, scrollViewer.ExtentWidth); Assert.AreEqual(border.Height, scrollViewer.ExtentHeight); border.Width = 1000; border.Height = 1000; Assert.AreEqual(Visibility.Visible, scrollViewer.ComputedHorizontalScrollBarVisibility); Assert.AreEqual(Visibility.Visible, scrollViewer.ComputedVerticalScrollBarVisibility); Assert.AreEqual(border.Width, scrollViewer.ExtentWidth); Assert.AreEqual(border.Height, scrollViewer.ExtentHeight); border.Width = 10; border.Height = 1000; Assert.AreEqual(Visibility.Collapsed, scrollViewer.ComputedHorizontalScrollBarVisibility); Assert.AreEqual(Visibility.Visible, scrollViewer.ComputedVerticalScrollBarVisibility); Assert.AreEqual(border.Width, scrollViewer.ExtentWidth); Assert.AreEqual(border.Height, scrollViewer.ExtentHeight); border.Width = 1000; border.Height = 10; Assert.AreEqual(Visibility.Visible, scrollViewer.ComputedHorizontalScrollBarVisibility); Assert.AreEqual(Visibility.Collapsed, scrollViewer.ComputedVerticalScrollBarVisibility); Assert.AreEqual(border.Width, scrollViewer.ExtentWidth); Assert.AreEqual(border.Height, scrollViewer.ExtentHeight); }
public void RoutedEventSourceTest() { string text = @" <ResourceDictionary xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests;assembly=Granular.Presentation.Tests' > <ControlTemplate x:Key='template1'> <StackPanel> <test:RoutedEventTestElement x:Name='child1' Width='100' Template='{DynamicResource template2}'/> </StackPanel> </ControlTemplate> <ControlTemplate x:Key='template2'> <StackPanel> <test:RoutedEventTestElement x:Name='child2' Width='200'/> </StackPanel> </ControlTemplate> </ResourceDictionary> "; ResourceDictionary resources = XamlLoader.Load(XamlParser.Parse(text)) as ResourceDictionary; RoutedEventTestElement root = new RoutedEventTestElement(); root.Resources = resources; root.Template = resources.GetValue("template1") as ControlTemplate; root.ApplyTemplate(); RoutedEventTestElement child1 = NameScope.GetTemplateNameScope(root).FindName("child1") as RoutedEventTestElement; child1.ApplyTemplate(); Assert.IsNotNull(child1); Assert.AreEqual(100, child1.Width); RoutedEventTestElement child2 = NameScope.GetTemplateNameScope(child1).FindName("child2") as RoutedEventTestElement; Assert.IsNotNull(child2); Assert.AreEqual(200, child2.Width); object source0 = null; object source1 = null; object source2 = null; root.Bubble += (sender, e) => source0 = e.Source; child1.Bubble += (sender, e) => source1 = e.Source; child2.Bubble += (sender, e) => source2 = e.Source; child2.RaiseEvent(new RoutedEventArgs(RoutedEventTestElement.BubbleEvent, child2)); Assert.AreEqual(root, source0); Assert.AreEqual(child1, source1); Assert.AreEqual(child2, source2); }
private static unsafe IntPtr ParseTemplate (Value *context_ptr, IntPtr resource_base, IntPtr surface, IntPtr binding_source, string xaml, ref MoonError error) { XamlContext context = Value.ToObject (typeof (XamlContext), context_ptr) as XamlContext; var parser = new XamlParser (context) { ResourceBase = UriHelper.FromNativeUri (resource_base), }; FrameworkElement fwe = null; var source = NativeDependencyObjectHelper.FromIntPtr (binding_source); if (source != null) { fwe = source as FrameworkElement; if (fwe == null) { error = new MoonError (parser.ParseException ("Only FrameworkElements can be used as TemplateBinding sources.")); return IntPtr.Zero; } } Log ("222222 ParseTemplateElement {0}", source); Log ("{0}", xaml); context.IsExpandingTemplate = true; context.TemplateOwner = source as DependencyObject; context.TemplateBindingSource = fwe; parser.HydrateObject = context.Template; INativeEventObjectWrapper dob = null; try { FrameworkTemplate template = parser.Parse (context.Node) as FrameworkTemplate; if (template != null) { dob = template.Content as INativeEventObjectWrapper; template.Content = null; } // No errors, but the template was just empty. if (dob == null) return IntPtr.Zero; } catch (Exception e) { error = new MoonError (e); return IntPtr.Zero; } finally { context.IsExpandingTemplate = false; context.TemplateOwner = null; context.TemplateBindingSource = null; } // XamlParser needs to ref its return value otherwise we can end up returning a an object to native // code with a refcount of '1' and it could then get GC'ed before we use it. Mono.NativeMethods.event_object_ref (dob.NativeHandle); return dob.NativeHandle; }
public ParseInformation CreateParseInformation() { var parser = new XamlParser(); return parser.Parse(this.FileName, this.Document, true, null, CancellationToken.None); }