Giter Site home page Giter Site logo

Comments (6)

whistyun avatar whistyun commented on June 16, 2024

Has a code which access Document property been tried here?

The initial value of Document property is null for now. And this vlaue is not changed until the Source or Markdown property value is changed.

MarkdownScrollViewer inherits from FlowDocumentScrollViewer. So the Document property can be initialized.

markdown.Document = new FlowDocument(new Paragraph(new Run("some text")));

Be careful not to change the Markdown and Source properties. These properties will update Document property.

from mdxaml.

rocksdanister avatar rocksdanister commented on June 16, 2024

Yes, It was old code from when using RichTextBox.

Maybe make Document setter private? initially being null before Markdown or Source can lead to mistakes like this.

from mdxaml.

whistyun avatar whistyun commented on June 16, 2024

The private access level prevents access to Document property.

I plan to change the Document getter so that it does not return null (it is automatically initialized).

public class MarkdownScrollViewer : FlowDocumentScrollViewer, IUriContext
{

    ・・・

    public new FlowDocument? Document
    {
        get
        {
            var bs = (FlowDocumentScrollViewer)this;
            return bs.Document ??= new FlowDocument();
        }
        set => ((FlowDocumentScrollViewer)this).Document = value;
    }
}

This is not an override, but hides accessible base property.
So if MarkdownScrollViewer is cast to FlowDocumentScrollViewer, the problem recurs.

var viewer1= new MarkdownScrollViewer();
viewer1.Document.Blocks.Add(...);  // No error occurres.

var viewer2 = (FlowDocumentScrollViewer)new MarkdownScrollViewer();
viewer2.Document.Blocks.Add(...);  // NullReferenceException occures

Would this amendment help you?

from mdxaml.

rocksdanister avatar rocksdanister commented on June 16, 2024

I think this is fine.

from mdxaml.

whistyun avatar whistyun commented on June 16, 2024

v1.17.0 has be released.
The Document does not return null (it is automatically initialized).

from mdxaml.

rocksdanister avatar rocksdanister commented on June 16, 2024

Great, I'll close this 🥳

from mdxaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.