|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using CommunityToolkit.WinUI.Controls; |
| 6 | + |
| 7 | +namespace MarkdownTextBlockExperiment.Samples; |
| 8 | + |
| 9 | +/// <summary> |
| 10 | +/// A sample demonstrating custom theming options for the MarkdownTextBlock control with live editing. |
| 11 | +/// </summary> |
| 12 | +[ToolkitSample(id: nameof(MarkdownTextBlockCustomThemeSample), "Custom Theme", description: "A sample showcasing custom theming options with live editing for headings, code blocks, quotes, tables, and more.")] |
| 13 | +public sealed partial class MarkdownTextBlockCustomThemeSample : MarkdownTextBlockCustomThemeSampleBase |
| 14 | +{ |
| 15 | + public MarkdownConfig MarkdownConfig { get; private set; } |
| 16 | + |
| 17 | + public string MarkdownText { get; } = @" |
| 18 | +# Custom Theme Demo |
| 19 | +
|
| 20 | +This sample demonstrates the **custom theming** capabilities of the `MarkdownTextBlock` control. |
| 21 | +
|
| 22 | +## Heading Styles |
| 23 | +
|
| 24 | +Each heading level has customizable foreground color, font size, weight, and margin. |
| 25 | +
|
| 26 | +### Heading 3 |
| 27 | +#### Heading 4 |
| 28 | +
|
| 29 | +## Inline Code |
| 30 | +
|
| 31 | +Here is some `inline code` with custom styling. Try adjusting the padding, corner radius, and colors in the editor panel! |
| 32 | +
|
| 33 | +Another example: `config.Themes.InlineCodePadding` |
| 34 | +
|
| 35 | +## Images |
| 36 | +
|
| 37 | +Images can be styled with max width, max height, and stretch options. Notice how the text flows naturally without any gaps above or below the image: |
| 38 | +
|
| 39 | + |
| 40 | +
|
| 41 | +The image above automatically scales to respect the max width setting while maintaining its aspect ratio. Text continues to flow seamlessly below it. |
| 42 | +
|
| 43 | +## Code Blocks |
| 44 | +
|
| 45 | +```csharp |
| 46 | +// Code blocks have custom styling too! |
| 47 | +public class CustomTheme |
| 48 | +{ |
| 49 | + public string Name { get; set; } |
| 50 | + public Color PrimaryColor { get; set; } |
| 51 | + |
| 52 | + public void ApplyTheme() |
| 53 | + { |
| 54 | + Console.WriteLine($""Applying theme: {Name}""); |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | +
|
| 59 | +## Block Quotes |
| 60 | +
|
| 61 | +> This is a styled block quote with custom background, |
| 62 | +> border color, padding, and corner radius. |
| 63 | +> |
| 64 | +> Try changing the border width and corner radius! |
| 65 | +
|
| 66 | +## Links |
| 67 | +
|
| 68 | +Check out [this link](https://github.com/CommunityToolkit) - links have custom foreground colors. |
| 69 | +
|
| 70 | +## Tables |
| 71 | +
|
| 72 | +| Feature | Status | Notes | |
| 73 | +|---------|--------|-------| |
| 74 | +| Headings | ✅ | Per-level colors | |
| 75 | +| Inline Code | ✅ | Full styling | |
| 76 | +| Code Blocks | ✅ | Background, border, font | |
| 77 | +| Quotes | ✅ | Border, background, radius | |
| 78 | +
|
| 79 | +--- |
| 80 | +
|
| 81 | +## Horizontal Rule |
| 82 | +
|
| 83 | +The line above is a horizontal rule with customizable thickness and margin. |
| 84 | +
|
| 85 | +## Lists |
| 86 | +
|
| 87 | +Try adjusting the **Bullet Spacing** and **Gutter Width** settings to see how list formatting changes! |
| 88 | +
|
| 89 | +- Top level list item |
| 90 | + - Nested item level 1 |
| 91 | + - Nested item level 2 |
| 92 | + - Nested item level 3 |
| 93 | +- Another top level item |
| 94 | +- Adjust the theme settings in the options panel |
| 95 | + - The gutter width controls how much each level is indented |
| 96 | + - The bullet spacing controls space after the bullet character |
| 97 | +- Click **Apply Changes** to see updates |
| 98 | +- Use **Reset to Defaults** to start over |
| 99 | +
|
| 100 | +Numbered lists work too: |
| 101 | +
|
| 102 | +1. First item |
| 103 | +2. Second item |
| 104 | + 1. Nested numbered item |
| 105 | + 2. Another nested item |
| 106 | + 1. Deep nesting works |
| 107 | +3. Third item |
| 108 | +"; |
| 109 | + |
| 110 | + public MarkdownTextBlockCustomThemeSample() |
| 111 | + { |
| 112 | + MarkdownConfig = new MarkdownConfig { Themes = CreateThemes() }; |
| 113 | + this.InitializeComponent(); |
| 114 | + } |
| 115 | + |
| 116 | + public override void ApplyTheme() |
| 117 | + { |
| 118 | + MarkdownConfig = new MarkdownConfig { Themes = CreateThemes() }; |
| 119 | + |
| 120 | + // Force re-render by toggling text |
| 121 | + MarkdownTextBlock.Config = MarkdownConfig; |
| 122 | + var text = MarkdownTextBlock.Text; |
| 123 | + MarkdownTextBlock.Text = ""; |
| 124 | + MarkdownTextBlock.Text = text; |
| 125 | + } |
| 126 | +} |
0 commit comments