Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8106799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:34:29+00:00 2026-06-06T00:34:29+00:00

Problem: I’m trying to access a named Run element within a FlowDocument which is

  • 0

Problem:

I’m trying to access a named Run element within a FlowDocument which is defined in the Window Resources. To clarify what I mean, consider the follow code:

<Window.Resources>
    <FlowDocument x:Key="doc">
        <Paragraph>
            <Run x:Name="run" />
        </Paragraph>
    </FlowDocument>
</Window.Resources>

Here, I’d be trying to access the Run element named “run.”

What I’ve Tried So Far:

  • Simply using the element’s name to access it. However, named elements in the window’s resources apparently don’t have the same default accessibility as elements defined in the window’s content, because this method did not work.

  • Attempting to add a key to the Run element and then accessing the element through the FindResource() method. Unfortunately, it seems that keys cannot be added to nested elements.

  • The following code, which throws a NullReferenceException:

    FlowDocument doc = (FlowDocument)FindResource("doc");
    ((Run)doc.FindName("run")).Text = "example text";
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:34:30+00:00Added an answer on June 6, 2026 at 12:34 am

    You can use LogicalTreeHelper.FindLogicalNode as

     var doc = this.Resources["doc"] as FlowDocument;
     ((Run)LogicalTreeHelper.FindLogicalNode(doc, "run")).Text = "example text";
    

    Remarks from above link:

    • The search direction for FindLogicalNode is toward child objects (down the tree); the search direction for the FindName methods is
      towards parent objects (up the tree).
    • The FindName methods are governed by the concept of a XAML namescope. Using FindName you are guaranteed that only one object of
      that name exists, because XAML namescopes enforce uniqueness. In
      contrast, FindLogicalNode ignores XAML namescope and might cross XAML
      namescope boundaries during the search.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have an address field from an Access database which has been converted
Problem When working with MasterPages, a common irritation I run into is that script
Problem description: Read an xml file, traverse to a particular node (element), if it
(Problem solved now, see answers below) Hello, in my app I am trying to
Problem Description: We have a service which has applications for main mobile OS’s. We
Problem: I need to get a random element for a container and also delete
Problem: If I pull my app's toolbar off of the window frame and float
Problem, simple and annoying. Im just trying to print a list of names, collected
Problem: Sometimes you will want to access a component from javascript with getElementById ,
Problem I have a protobuf message definition with a MessageType field, which is an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.