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

  • Home
  • SEARCH
  • 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 629503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:45:12+00:00 2026-05-13T19:45:12+00:00

Thanks to Leom’s answer I was able to add a FlowDocument to a StackPanel

  • 0

Thanks to Leom’s answer I was able to add a FlowDocument to a StackPanel by wrapping it in a FlowDocumentReader.

But now I have two problems:

  • it seems only the first FlowDocumentReader is added and the rest ignored
  • there is an unwanted margin that I can’t get rid of

How can I add multiple FlowDocumentReaders to a StackPanel without the unwanted margin?

alt text http://www.deviantsart.com/upload/1ndiqqe.png

XAML:

<Window x:Class="TestFlowdoc23432.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="200" Width="300">
    <StackPanel Margin="10">
        <ContentControl x:Name="MainArea"/>
    </StackPanel>
</Window>

Code Behind:

using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

namespace TestFlowdoc23432
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            StackPanel sp = new StackPanel();

            TextBlock tb1 = new TextBlock();
            tb1.Text = "first text block";
            sp.Children.Add(tb1);

            TextBlock tb2 = new TextBlock();
            tb2.Text = "second text block";
            sp.Children.Add(tb2);

            sp.Children.Add(GetFlowDocumentReader("first flow document reader"));
            sp.Children.Add(GetFlowDocumentReader("second flow document reader"));

            MainArea.Content = sp;
        }

        FlowDocumentReader GetFlowDocumentReader(string text)
        {
            FlowDocumentReader fdr = new FlowDocumentReader();
            FlowDocument fd = new FlowDocument();
            fdr.Document = fd;
            fdr.Margin = new Thickness(0);
            Paragraph par = new Paragraph();
            par.Margin = new Thickness(0);
            fd.Blocks.Add(par);

            Run r = new Run(text);
            par.Inlines.Add(r);

            return fdr;
        }

    }
}
  • 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-05-13T19:45:12+00:00Added an answer on May 13, 2026 at 7:45 pm

    To make the text appear to the left you need to set the pagepadding property on your flowdocument as follows:

    fd.PagePadding = new Thickness(0);
    

    the reason that you only seem to get the first reader is becuase it fills the space available (move it to be the first object and you will not see the textblocks).
    If you change the FlowDocumentReader to be a FlowDocumentScrollViewer and use the VerticalScrollBarVisibility property then you can get the desired effect. The following is your GetFlowDocumentReader method with the changes applied:

    FlowDocumentScrollViewer GetFlowDocumentReader(string text)
            {
                FlowDocumentScrollViewer fdr = new FlowDocumentScrollViewer();
    
                FlowDocument fd = new FlowDocument();
                fdr.Document = fd;
                fdr.Margin = new Thickness(0);
                Paragraph par = new Paragraph();
                par.Margin = new Thickness(0);
                fd.Blocks.Add(par);
    
                Run r = new Run(text);
                par.Inlines.Add(r);
    
                fd.PagePadding = new Thickness(0);
                fdr.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
    
                return fdr;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks to the epic work of Dennis Williamson, I am now able to calculate
Thanks for reading my question. I have searched for and read similar questions, but
thanks to Stof on IRC i know the answer now. I just wanted to
Thanks for reading this. I have no idea why this is throwing a NullReferenceException
Thanks in advance for your help. I have a need within an application to
Thanks for reading. I have done a search, read multiple posts (lost count) and
Thanks in advance for your time. I have a deeply nested XML whose XSLT
Thanks in Advance.... Can any one knows, I have a requirement to perfrom OnclickListener
Thanks for viewing my question. So, I have a question with iframes. I want
Thanks in advance I attached a device to my mac but it is not

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.