Пример #1
0
        private static void OnTextFormatterTypeChanged(DependencyObject dependencyObject,
                                                       DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            var textBox = (BindableHtmlRichTextBox)dependencyObject;

            var            formatterType = (TextFormatterType)dependencyPropertyChangedEventArgs.NewValue;
            ITextFormatter formatter     = new RtfFormatter();

            switch (formatterType)
            {
            case TextFormatterType.Html:
                formatter = new HtmlFormatter();
                break;

            case TextFormatterType.Rtf:
                formatter = new RtfFormatter();
                break;

            case TextFormatterType.PlainText:
                formatter = new PlainTextFormatter();
                break;

            case TextFormatterType.Xaml:
                formatter = new XamlFormatter();
                break;

            case TextFormatterType.Default:
                break;
            }
            textBox.TextFormatter = formatter;
        }
Пример #2
0
        public void CanFormatElementSyntaxCorrectly()
        {
            //Arrange
            string xaml =
                @"<DialogHost>
  <Border>
    <Button>RUN</Button>
  </Border>
</DialogHost>";

            var formatter = new XamlFormatter {
                Indent = "  "
            };

            //Act
            var formatted = formatter.FormatXaml(xaml);

            //Assert
            Assert.AreEqual(@"<DialogHost>
  <Border>
    <Button>
      RUN
    </Button>
  </Border>
</DialogHost>".NormalizeLineEndings(), formatted.NormalizeLineEndings());
        }
Пример #3
0
        public void CanIgnoreElementSyntaxChildren()
        {
            //Arrange
            string xaml = @"
<StackPanel showMeTheXaml:XamlDisplay.Ignore=""This"" xmlns:showMeTheXaml=""clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"">
  <StackPanel.Resources>
    <Style TargetType=""Button"" />
  </StackPanel.Resources>
  <Button>
    <TextBlock Text=""Some Text"" />
  </Button>
  <Button />
</StackPanel>";

            var formatter = new XamlFormatter {
                Indent = "  "
            };

            //Act
            var formatted = formatter.FormatXaml(xaml);

            //Assert
            Assert.AreEqual(@"<Button>
  <TextBlock Text=""Some Text"" />
</Button>
<Button />".NormalizeLineEndings(), formatted.NormalizeLineEndings());
        }
Пример #4
0
        public void HandlesRemovingNamespaces()
        {
            //Arrange
            string xaml =
                @"<smtx:XamlDisplay Key=""list_3"" Style=""{StaticResource PopupXamlDisplay}"" Grid.Column=""2"" Grid.Row=""0"" xmlns:smtx=""clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"">
  <!-- and here's another -->
  <ItemsControl ItemsSource=""{Binding Items2}"" Grid.IsSharedSizeScope=""True"" xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
    <ItemsControl.ItemTemplate>
      <DataTemplate DataType=""{x:Type domain:SelectableViewModel}"">
        <Border x:Name=""Border"" Padding=""8"" BorderThickness=""0 0 0 1"" BorderBrush=""{DynamicResource MaterialDesignDivider}"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
          
        </Border>
      </DataTemplate>
    </ItemsControl.ItemTemplate>
  </ItemsControl>
</smtx:XamlDisplay>";

            var formatter = new XamlFormatter {
                Indent = "  "
            };

            //Act
            var formatted = formatter.FormatXaml(xaml);

            //Assert
            Assert.AreEqual(@"<!-- and here's another -->
<ItemsControl ItemsSource=""{Binding Items2}"" Grid.IsSharedSizeScope=""True"">
  <ItemsControl.ItemTemplate>
    <DataTemplate DataType=""{x:Type domain:SelectableViewModel}"">
      <Border x:Name=""Border"" Padding=""8"" BorderThickness=""0 0 0 1"" BorderBrush=""{DynamicResource MaterialDesignDivider}""></Border>
    </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl>".NormalizeLineEndings(), formatted.NormalizeLineEndings());
        }
Пример #5
0
 private void NoteView_OnLoaded(object sender, RoutedEventArgs e)
 {
     _xamlFormatter = Resources["XamlFormatter"] as XamlFormatter;
     _markdownToFlowDocumentConverter = Resources["TextToFlowDocumentConverter"] as TextToFlowDocumentConverter;
     if (_xamlFormatter != null)
     {
         _xamlFormatter.CheckBoxCheckedCommand = new SimpleCommand(DocumentCheckBoxChecked);
     }
 }
Пример #6
0
        private void NoteView_OnLoaded(object sender, RoutedEventArgs e)
        {
            _xamlFormatter = Resources["XamlFormatter"] as XamlFormatter;
            _markdownToFlowDocumentConverter = Resources["TextToFlowDocumentConverter"] as TextToFlowDocumentConverter;
            Model.MarkdownConverter          = _markdownToFlowDocumentConverter;
            if (_xamlFormatter != null)
            {
                _xamlFormatter.CheckBoxCheckedCommand = new SimpleCommand(DocumentCheckBoxChecked);
            }

            Messenger.Default.Send(new ApplicationPartLoaded(ApplicationPartLoaded.ApplicationParts.NoteView));
        }
Пример #7
0
        public void CanIgnoreTopLevelElement()
        {
            //Arrange
            string xaml = @"
<StackPanel showMeTheXaml:XamlDisplay.Ignore=""This"" xmlns:showMeTheXaml=""clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"">
  <Button />

  <Button />
</StackPanel>";

            var formatter = new XamlFormatter();

            //Act
            var formatted = formatter.FormatXaml(xaml);

            //Assert
            Assert.AreEqual("<Button />\r\n<Button />".NormalizeLineEndings(), formatted.NormalizeLineEndings());
        }
Пример #8
0
        private void SaveDesigner()
        {
            try
            {
                _isSavingDesigner = true;

                var vm = this.DataContext as XamlDocument;

                var sb = new StringBuilder();

                using (var xamlWriter = new ICSharpCode.WpfDesign.XamlDom.XamlXmlWriter(sb))
                {
                    designControl.SaveDesigner(xamlWriter);
                    vm.AvalonDocument.Text = XamlFormatter.Format(sb.ToString());
                }

                _isSavingDesigner = false;
            }
            catch (Exception)
            {
            }
        }
Пример #9
0
        public void CanRemoveXamlDisplayDeclaration()
        {
            //Arrange
            string xaml =
                @"<smtx:XamlDisplay Key=""list_2"" xmlns:smtx=""clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"">
  <!-- some comment -->
  <ItemsControl ItemsSource=""{Binding Items1}"" Grid.IsSharedSizeScope=""True"" Margin=""12 0 12 0"" xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
    
  </ItemsControl>
</smtx:XamlDisplay>";

            var formatter = new XamlFormatter {
                Indent = "  "
            };

            //Act
            var formatted = formatter.FormatXaml(xaml);

            //Assert
            Assert.AreEqual(@"<!-- some comment -->
<ItemsControl ItemsSource=""{Binding Items1}"" Grid.IsSharedSizeScope=""True"" Margin=""12 0 12 0""></ItemsControl>".NormalizeLineEndings(), formatted.NormalizeLineEndings());
        }