|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Customize Appearance in .NET MAUI MarkdownViewer | Syncfusion |
| 4 | +description: Learn how to style and customize the appearance of Markdown content using the MarkdownStyleSettings class in the Syncfusion .NET MAUI MarkdownViewer control. |
| 5 | +platform: MAUI |
| 6 | +control: SfMarkdownViewer |
| 7 | +documentation: ug |
| 8 | +--- |
| 9 | + |
| 10 | +# Customize Appearance in .NET MAUI SfMarkdownViewer |
| 11 | + |
| 12 | +The [SfMarkdownViewer]() control in .NET MAUI provides a powerful styling system through the `MarkdownStyleSettings` class. This allows developers to customize the visual presentation of Markdown content with precision and flexibility. |
| 13 | + |
| 14 | +## Key Features |
| 15 | + |
| 16 | +- **Granular Styling**: Customize font sizes and colors for headings, body text, and tables. |
| 17 | +- **Custom CSS Support**: Apply advanced styling using raw CSS rules. |
| 18 | +- **Two-Layer Styling System**: Merge base styles with custom CSS for full control. |
| 19 | +- **Reset Functionality**: Revert all styles to default with a single method call. |
| 20 | + |
| 21 | +## Use Cases |
| 22 | + |
| 23 | +- Match Markdown content appearance with your app’s theme. |
| 24 | +- Improve readability with tailored font sizes and spacing. |
| 25 | +- Highlight specific Markdown elements like tables or code blocks. |
| 26 | +- Apply branding styles using custom CSS. |
| 27 | + |
| 28 | +## Customization with MarkdownStyleSettings |
| 29 | + |
| 30 | +The appearance of headings and body content in SfMarkdownViewer can be customized using the MarkdownStyleSettings class. |
| 31 | + |
| 32 | +[H1FontSize](), [H2FontSize](), [H3FontSize]() – Gets or sets the font size for H1, H2, and H3 heading elements respectively. |
| 33 | + |
| 34 | +[H1Color](), [H2Color](), [H3Color]() – Gets or sets the text color for H1, H2, and H3 heading elements respectively. |
| 35 | + |
| 36 | +[BodyFontSize]() – Gets or sets the font size for regular paragraph text. |
| 37 | + |
| 38 | +[BodyTextColor]() – Gets or sets the text color for body content. |
| 39 | + |
| 40 | +[TableHeaderFontSize](), [TableDataFontSize]() – Gets or sets the font size for table headers and table content respectively. |
| 41 | + |
| 42 | +[TableHeaderTextColor](), [TableDataTextColor]() – Gets or sets the text color for table headers and table content respectively. |
| 43 | + |
| 44 | +[TableBackground]() – Gets or sets the background color for the entire table area. |
| 45 | + |
| 46 | +[CssStyleRules]() – Gets or sets raw CSS styles to override or extend default Markdown rendering behavior. |
| 47 | + |
| 48 | +{% tabs %} |
| 49 | +{% highlight xaml %} |
| 50 | + |
| 51 | + <ContentPage> |
| 52 | + . . . |
| 53 | + <markdown:SfMarkdownViewer Source={Binding MarkdownContent}> |
| 54 | + <markdown:SfMarkdownViewer.Settings> |
| 55 | + <markdown:MarkdownStyleSettings H1FontSize = "32px" |
| 56 | + H1Color = "#8352FB" |
| 57 | + H2Color = "#9971FB" |
| 58 | + H3Color = "#A98AF7" |
| 59 | + BodyFontSize = "16px" |
| 60 | + BodyTextColor = "#2C3E50" |
| 61 | + TableBackground = "#FFE2ED" |
| 62 | + TableHeaderTextColor = "HotPink"> |
| 63 | + </markdown:MarkdownStyleSettings> |
| 64 | + </markdown:SfMarkdownViewer.Settings> |
| 65 | + </markdown:SfMarkdownViewer> |
| 66 | + . . . |
| 67 | + </ContentPage> |
| 68 | + |
| 69 | +{% endhighlight %} |
| 70 | + |
| 71 | +{% highlight C# %} |
| 72 | + |
| 73 | + public partial class MainPage : ContentPage |
| 74 | + { |
| 75 | + . . . |
| 76 | + |
| 77 | + public MainPage() |
| 78 | + { |
| 79 | + InitializeComponent(); |
| 80 | + |
| 81 | + SfMarkdownViewer markdownViewer = new SfMarkdownViewer(); |
| 82 | + markdownViewer.Source = MarkdownContent; |
| 83 | + MarkdownViewer.Settings = new MarkdownStyleSettings() |
| 84 | + { |
| 85 | + H1FontSize = "32px", |
| 86 | + H1Color = "#8352FB", |
| 87 | + H2Color = "#9971FB", |
| 88 | + H3Color = "#A98AF7", |
| 89 | + BodyFontSize = "16px", |
| 90 | + BodyTextColor = "#2C3E50", |
| 91 | + TableBackground = "#FFE2ED", |
| 92 | + TableHeaderTextColor = "HotPink" |
| 93 | + }; |
| 94 | + |
| 95 | + Content = markdownViewer; |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | +{% endhighlight %} |
| 100 | +{% endtabs %} |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +With [MarkdownStyleSettings](), you gain full control over how Markdown content looks in your .NET MAUI app—whether you're building a documentation viewer, a note-taking app, or a styled content portal. |
0 commit comments