Darkhydro
Darkhydro

Reputation: 2072

WPF FlowDocument space size is inconsistent

I'm using a FlowDocumentScrollViewer to print out log outputs to my application window, and am getting some rather weird spacing issues. Most of the spaces are correctly sized, but I'll consistently get way too large of spaces in some areas. Here's an example:

Correctly spaced: "d Copying E:\Projects"
What is displayed: "d      Copying      E:\Projects"

I had to use multiple spaces to reflect the spacing issue above, but I guarantee that it is indeed just displaying one space, incorrectly sized. This is easily verifiable by copying the text from my FlowDocumentScrollViewer into a text editor like notepad++. Here's the printing code for my simplest FlowDocumentScrollViewer:

LogBox.Document = new FlowDocument();
LogBox.Document.Background = LogBox.Background;
LogBox.Document.Foreground = LogBox.Foreground;
LogBox.Document.Blocks.Add(logParagraph = new Paragraph());
logParagraph.Margin = new Thickness(0); //Tested making Margin 0, didn't help
logParagraph.FontFamily = font;
logParagraph.FontSize = defaultFontSize;

...

public void PrintLog(String s)
{
    logParagraph.Inlines.Add(s);
}

I've never seen anything like this, and searching for it on google is very difficult since everyone that uses "spacing" as a keyword really means line height... any help is appreciated.

Upvotes: 0

Views: 388

Answers (2)

c_str
c_str

Reputation: 389

Have you tried...

LogBox.TextAlignment = TextAlignment.Left;

and / or

logParagraph.TextAlignment = TextAlignment.Left;

owo? Because as I can see, in some cases the Block is getting an auto alignments to justify / stretch the text in the line~ Don't know why but seems to happen ;o

Upvotes: 4

Jonathon Lee
Jonathon Lee

Reputation: 211

You could try adding a Run object in the PrintLog method, and modifying its properties like CharacterSpacing, and maybe try other ones as well. Sorry I don't have access to Visual Studio at the moment so I can't actually try it.

public void PrintLog(String s)
{
     var run = new Run();
     // modify run properties here    
    logParagraph.Inlines.Add(run);
}

You can view the MS documentation here: Run Class

Upvotes: 1

Related Questions