diff --git a/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSample.xaml b/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSample.xaml index 326987686..5da90bafc 100644 --- a/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSample.xaml +++ b/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSample.xaml @@ -1,4 +1,4 @@ - + diff --git a/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSample.xaml.cs b/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSample.xaml.cs index 127efbee0..eb83d7024 100644 --- a/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSample.xaml.cs +++ b/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSample.xaml.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using CommunityToolkit.WinUI.Controls; - namespace MarkdownTextBlockExperiment.Samples; /// @@ -12,8 +10,6 @@ namespace MarkdownTextBlockExperiment.Samples; [ToolkitSample(id: nameof(MarkdownTextBlockCustomThemeSample), "Custom Theme", description: "A sample showcasing custom theming options with live editing for headings, code blocks, quotes, tables, and more.")] public sealed partial class MarkdownTextBlockCustomThemeSample : MarkdownTextBlockCustomThemeSampleBase { - public MarkdownConfig MarkdownConfig { get; private set; } - public string MarkdownText { get; } = @" # Custom Theme Demo @@ -96,7 +92,7 @@ Try adjusting the **Bullet Spacing** and **Gutter Width** settings to see how li - Adjust the theme settings in the options panel - The gutter width controls how much each level is indented - The bullet spacing controls space after the bullet character -- Click **Apply Changes** to see updates +- Changes apply live via bindings - Use **Reset to Defaults** to start over Numbered lists work too: @@ -109,20 +105,24 @@ 1. Deep nesting works 3. Third item "; + // Converter methods for x:Bind function bindings (must be on the x:Class type, not the base) + public Brush GetHeadingBrush(int index) => HeadingColors[Math.Clamp(index, 0, HeadingColors.Length - 1)]; + public Brush GetInlineCodeBrush(int index) => InlineCodeColors[Math.Clamp(index, 0, InlineCodeColors.Length - 1)]; + public Brush GetCodeBackgroundBrush(int index) => CodeBackgroundColors[Math.Clamp(index, 0, CodeBackgroundColors.Length - 1)]; + public Brush GetCodeBorderBrush(int index) => CodeBorderColors[Math.Clamp(index, 0, CodeBorderColors.Length - 1)]; + public Brush GetQuoteBrush(int index) => QuoteColors[Math.Clamp(index, 0, QuoteColors.Length - 1)]; + public FontFamily GetCodeFont(int index) => CodeFonts[Math.Clamp(index, 0, CodeFonts.Length - 1)]; + public Stretch GetImageStretch(int index) => ImageStretchOptions[Math.Clamp(index, 0, ImageStretchOptions.Length - 1)]; + public Windows.UI.Text.FontWeight GetBoldFontWeight(int index) => BoldFontWeights[Math.Clamp(index, 0, BoldFontWeights.Length - 1)]; + public Thickness GetUniformThickness(double value) => new Thickness(value); + public CornerRadius GetUniformCornerRadius(double value) => new CornerRadius(value); + public Thickness GetHorizontalPadding(double value) => new Thickness(value, value / 2, value, value / 2); + public Thickness GetLeftBorderThickness(double value) => new Thickness(value, 0, 0, 0); + public CornerRadius GetRightCornerRadius(double value) => new CornerRadius(0, value, value, 0); + public Thickness GetVerticalMargin(double value) => new Thickness(0, value, 0, value); + public MarkdownTextBlockCustomThemeSample() { - MarkdownConfig = new MarkdownConfig { Themes = CreateThemes() }; this.InitializeComponent(); } - - public override void ApplyTheme() - { - MarkdownConfig = new MarkdownConfig { Themes = CreateThemes() }; - - // Force re-render by toggling text - MarkdownTextBlock.Config = MarkdownConfig; - var text = MarkdownTextBlock.Text; - MarkdownTextBlock.Text = ""; - MarkdownTextBlock.Text = text; - } } diff --git a/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSampleBase.cs b/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSampleBase.cs index c1c49e5d2..4768e7a90 100644 --- a/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSampleBase.cs +++ b/components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSampleBase.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using CommunityToolkit.WinUI.Controls; using Microsoft.UI; using Windows.UI; @@ -14,7 +13,7 @@ namespace MarkdownTextBlockExperiment.Samples; -public abstract partial class MarkdownTextBlockCustomThemeSampleBase : Page +public partial class MarkdownTextBlockCustomThemeSampleBase : Page { // Dependency properties for theme customization public static readonly DependencyProperty H1FontSizeProperty = @@ -372,67 +371,7 @@ public double ListGutterWidth FontWeights.ExtraBold }; - public MarkdownThemes CreateThemes() - { - return new MarkdownThemes - { - H1FontSize = H1FontSize, - H1FontWeight = FontWeights.Bold, - H1Foreground = HeadingColors[H1ColorIndex], - H1Margin = new Thickness(0, 20, 0, 10), - - H2FontSize = H2FontSize, - H2FontWeight = FontWeights.SemiBold, - H2Foreground = new SolidColorBrush(Colors.MediumSlateBlue), - - H3FontSize = H3FontSize, - H3FontWeight = FontWeights.SemiBold, - H3Foreground = new SolidColorBrush(Colors.MediumPurple), - - InlineCodeFontSize = InlineCodeFontSize, - InlineCodePadding = new Thickness(InlineCodePadding, InlineCodePadding / 2, InlineCodePadding, InlineCodePadding / 2), - InlineCodeCornerRadius = new CornerRadius(InlineCodeCornerRadius), - InlineCodeBorderThickness = new Thickness(InlineCodeBorderThickness), - InlineCodeForeground = InlineCodeColors[InlineCodeColorIndex], - InlineCodeBackground = CodeBackgroundColors[InlineCodeBackgroundColorIndex], - InlineCodeBorderBrush = CodeBorderColors[InlineCodeBorderColorIndex], - - CodeBlockPadding = new Thickness(CodeBlockPadding), - CodeBlockCornerRadius = new CornerRadius(CodeBlockCornerRadius), - CodeBlockBorderThickness = new Thickness(CodeBlockBorderThickness), - CodeBlockFontFamily = CodeFonts[CodeBlockFontIndex], - CodeBlockBackground = CodeBackgroundColors[CodeBlockBackgroundColorIndex], - CodeBlockForeground = new SolidColorBrush(Colors.LightGreen), - CodeBlockBorderBrush = CodeBorderColors[CodeBlockBorderColorIndex], - - QuoteBorderThickness = new Thickness(QuoteBorderWidth, 0, 0, 0), - QuotePadding = new Thickness(QuotePadding, QuotePadding / 2, QuotePadding, QuotePadding / 2), - QuoteCornerRadius = new CornerRadius(0, QuoteCornerRadius, QuoteCornerRadius, 0), - QuoteBorderBrush = QuoteColors[QuoteColorIndex], - QuoteBackground = new SolidColorBrush(Color.FromArgb(20, 100, 149, 237)), - QuoteForeground = new SolidColorBrush(Colors.CornflowerBlue), - - TableCellPadding = new Thickness(TableCellPadding, TableCellPadding / 2, TableCellPadding, TableCellPadding / 2), - TableBorderThickness = TableBorderThickness, - TableBorderBrush = new SolidColorBrush(Colors.SlateGray), - TableHeadingBackground = new SolidColorBrush(Color.FromArgb(40, 100, 149, 237)), - HorizontalRuleThickness = HorizontalRuleThickness, - HorizontalRuleMargin = new Thickness(0, HorizontalRuleMargin, 0, HorizontalRuleMargin), - HorizontalRuleBrush = new SolidColorBrush(Colors.MediumSlateBlue), - - LinkForeground = new SolidColorBrush(Colors.DeepSkyBlue), - - ImageMaxWidth = ImageMaxWidth, - ImageMaxHeight = ImageMaxHeight, - ImageStretch = ImageStretchOptions[ImageStretchIndex], - - BoldFontWeight = BoldFontWeights[BoldFontWeightIndex], - - ListBulletSpacing = ListBulletSpacing, - ListGutterWidth = ListGutterWidth, - }; - } public void ResetToDefaults() { @@ -476,6 +415,4 @@ public void ResetToDefaults() ListBulletSpacing = 4; ListGutterWidth = 30; } - - public abstract void ApplyTheme(); } diff --git a/components/MarkdownTextBlock/samples/MarkdownTextBlockExampleSample.xaml b/components/MarkdownTextBlock/samples/MarkdownTextBlockExampleSample.xaml index 043e52c46..ad89fdf6f 100644 --- a/components/MarkdownTextBlock/samples/MarkdownTextBlockExampleSample.xaml +++ b/components/MarkdownTextBlock/samples/MarkdownTextBlockExampleSample.xaml @@ -11,7 +11,6 @@ _config; - set => _config = value; - } - public string Text { get => _text; @@ -600,7 +593,6 @@ public string Text public MarkdownTextBlockExampleSample() { this.InitializeComponent(); - _config = new MarkdownConfig(); _text = _markdown; MarkdownTextBlock.OnLinkClicked += MarkdownTextBlock_OnLinkClicked; } diff --git a/components/MarkdownTextBlock/samples/ThemeOptionsPane.xaml b/components/MarkdownTextBlock/samples/ThemeOptionsPane.xaml index 4946ef686..99f2f1c44 100644 --- a/components/MarkdownTextBlock/samples/ThemeOptionsPane.xaml +++ b/components/MarkdownTextBlock/samples/ThemeOptionsPane.xaml @@ -15,9 +15,6 @@ Spacing="8">