Skip to content
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

MarkdownStyle is being overridden in constructor #34

Closed
rzinnatullin opened this issue May 12, 2022 · 2 comments
Closed

MarkdownStyle is being overridden in constructor #34

rzinnatullin opened this issue May 12, 2022 · 2 comments

Comments

@rzinnatullin
Copy link

rzinnatullin commented May 12, 2022

There is MarkdownStyle property in MarkdownScrollViewer control.
It can be set directly, or via a style.
However, setting it via a style does not work, because its value is being overridden by Standard Markdown style:

        public MarkdownScrollViewer()
        {
            Engine = new Markdown();
            SetCurrentValue(MarkdownStyleNameProperty, nameof(MdStyle.Standard));
        }

The overriding is happening in MarkdownStyleNameProperty change handler (UpdateStyleName method):

owner.MarkdownStyle = (Style)prop.GetValue(null);

Please fix the issue.

@rzinnatullin
Copy link
Author

To workaround the issue I've created a descendant class and added the MarkdownStyleFixed property which I set in a style:

    public class MarkdownViewer : MarkdownScrollViewer
    {
        public static readonly DependencyProperty MarkdownStyleFixedProperty =
            DependencyProperty.Register(
                nameof(MarkdownStyleFixed),
                typeof(Style),
                typeof(MarkdownViewer),
                new PropertyMetadata(null, UpdateMarkdownStyleFixed));

        public Style? MarkdownStyleFixed
        {
            get => (Style)GetValue(MarkdownStyleFixedProperty);
            set => SetValue(MarkdownStyleFixedProperty, value);
        }

        private static void UpdateMarkdownStyleFixed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = (MarkdownScrollViewer)d;
            control.MarkdownStyle = (Style)e.NewValue;
        }

        public override void EndInit()
        {
            base.EndInit();
            if (MarkdownStyleFixed != null && MarkdownStyleFixed != MarkdownStyle)
            {
                MarkdownStyle = MarkdownStyleFixed;
            }
        }
    }

Hope this helps to someone until the original issue is fixed.

@whistyun
Copy link
Owner

I released v1.15.
Setting a value to MarkdownStyleName in constructor is removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants