How to add xaml code to c # comment?

/// <summary> /// /// </summary> /// <remarks /// /// </remarks> 

How to add xaml code to the above comment, avoiding the code parser to create links that do not exist (CTRL + Click messages)?

+4
source share
3 answers

You have two options:

  • XML standard deletion

    /// &lt;TextBlock Text=&quot;Hello World!&quot;/&gt;

  • CDATA sections

    /// <![CDATA[<TextBlock Text="Hello World!"/>]]>

With the first parameter, Visual Studio Intellisense will correctly display the raw XML sequence.

+6
source

In the XAML view, put some XAML that you want to use as a comment

Then surround him

 <!-- #region XAML Snippet --> <StackPanel> <Button Content="Click me, I do nothing!" /> </StackPanel> <!-- #endregion --> 

Note. I put this in the MainWindow.xaml file, but it can be any XAML file.

Now in C # use this as a comment:

 /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> /// <example> /// <code source="MyProject.Namespace/MainWindow.xaml" region="XAML snippet" lang="XAML" title="A linked *.xaml file treated as XAML"/> /// </example> 

SandCastle understands this syntax and generates the appropriate documentation (for example, on MSDN), however it will not appear in intellisense.

You can format a regular <summary> body with &gt; and &lt; instead of < > characters to mimic the XAML syntax, but it will be a pain.

+6
source

Use CDATA tags?

 /// <summary> /// <![CDATA[<StackPanel />]]> /// </summary> 

Note. This will not appear in Intellisense, so if this is a requirement, this method will not work for your scenario.

Why do you want to add XAML to the code file?

+2
source

Source: https://habr.com/ru/post/1435503/


All Articles