0

I'm building the documentation page of Xamarin app in Blazor and I've encountered a problem. I'd like to show code snippets on the page using razor page. So far, I don't have that big problem with C# code, for example of App.xaml.cs:

public App()
   {
     InitializeComponent();
   }

For something like that - I don't have any problems. I can correctly style it as <code> tag, with CSS or with MudBlazor (which I'm also using). Also, IDE is not recognizing it as inside-code. The problem however is when:

a) I'm trying to add XAML code / tags

b) I'm trying to add some C# methods from Xamarin and they include tags, for example:

_container.Resolve<WebService> ...

So the IDE is recognizing <WebService> as something inside Blazor app.

Of course, I was already trying with <code> blocks with no success. Is there any way to make it work? I really need to show those in documentation so I'm a the dead point right now.

4
  • 3
    Please show your failing example to blazorfiddle.com and I'll take a look. I just tried <code>@("_container.Resolve<WebService>")</code> and it's rendered properly. Commented Feb 11, 2022 at 14:16
  • @BaneBojanić Thanks, I tried it and worked for that specific example. However for XAML code snippet, it is not working. Here's fiddle: blazorfiddle.com/s/npcpt230 Commented Feb 11, 2022 at 14:26
  • 2
    is this okay? blazorfiddle.com/s/ju09qgj2 Commented Feb 11, 2022 at 14:43
  • @BaneBojanić Seems fine but is there any solution If I would like to include it as totally same as from application? So basically as You have the style for: white-space: pre to include line breaks? I've found solution with using &lt; and &gt; as replacements but I'm wondering if there is a better one. Commented Feb 11, 2022 at 14:45

1 Answer 1

1

You have to escape the quotes. I also added some \r\n and a \t to demonstrate formatting with <pre>

@page "/"
<pre>
    <code>@someString</code>
</pre>
@code {
      string someString = "<Application.Resources>\r\n\t<Color x:Key=\"PrimaryText\">#777777</Color><Application.Resources>";
}

Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

That's just perfect. I've also found solution with replacing opening tags with &lt; sign and I was also able to successfully show it on page. However - I will use Your solution probably. Thank You!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.