-
Notifications
You must be signed in to change notification settings - Fork 15
[Gallery] Colorcoding for code snippets #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -9,8 +9,10 @@ | |||
xmlns:renderer="using:CommunityToolkit.App.Shared.Renderers" | |||
xmlns:wasm="http://uno.ui/wasm" | |||
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:xamarin="http://uno.ui/xamarin" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Arlodotexe @michael-hawker I got this using from the Uno.CommunityToolkit
sample app repo.. and it works, but not sure if this is the right one :-)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Arlodotexe thoughts on this bit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if they'll be keeping xamarin
long term, if we're keeping this we should use not_win
instead.
Though I think this becomes extra if we create the composed (not inherited) markdown textblock, since we can use our C# compilation conditionals.
Style="{StaticResource CaptionTextBlockStyle}" | ||
Text="{x:Bind CSharpCode, Mode=OneWay}" /> | ||
<StackPanel Orientation="Vertical"> | ||
<xamarin:TextBlock x:Name="CSharpCodeRenderer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an add-on to this, we could take the same approach I did for the MarkdownTextBlock
in the sample app, and create a wrapper around TextBlock, but on WASM we call the ColorCode HTML generator and then inject that HTML into the control...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you could just encapsulate all this XAML stuff and the code into the control, like the MarkdownTextBlock helper does: https://github.com/CommunityToolkit/Tooling-Windows-Submodule/blob/main/CommunityToolkit.App.Shared/Renderers/Markdown/MarkdownTextBlock.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-hawker I was thinking, for UWP/WinUI I'd base the CodeRenderer
on RichTextBlock
, right? But that would be sealed
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, forgot about that (and thus why sealing UI controls is generally annoying...) - Linking to microsoft/microsoft-ui-xaml#780 as usual...
I guess for the native platform you could have a ContentPresenter
or something and stick in a RTB, or create a local UserControl or something that just wraps a RTB within it? Have it expose a Text
property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was thinking maybe we can just use composition instead of inheritance, i.e. wrap everything in just a Control
, and that control can setup it's content based on platform, on WinUI2/3 it sets it as a RTB and uses ColorCode directly, for WASM it sets it to a TextBlock or whatever but replaces the HTML content with the ColorCode output, and then on other Uno targets it just uses a TextBlock with the raw text? The control can just expose a general Text
property that can be passed in the Markdown from the ToolkitSampleRenderer, so then the renderer doesn't care about the platform.
@niels9001 what did you want to do here? Should we just commit this as-is for now or did you want to take a stab at the above?
Talked to @niels9001, since the control will be harder to build than we thought with RTB being sealed, we'll just merge this working approach in as-is for now and revisit later. I'm updating this with main and will re-test |
@michael-hawker Think that was why we decided on using composition instead of inheritance a few weeks ago (see your comment here). |
b7ce348
to
83a16c2
Compare
Oops, rebased on top of #131 as I was testing... needs that merged first |
83a16c2
to
0e993ad
Compare
Addressing: #104
WASM doesn't support
RichTextBlock
, so we're falling back on a regularTextBlock
there.UWP/WASDK:

WASM:
