Resolved What's the best way to handle a lot of text?

glasswizzard

Well-known member
Joined
Nov 22, 2019
Messages
126
Programming Experience
Beginner
Well, not exactly a lot, more like a small paragraph, maybe two. I've been looking at the flowdocument to build up the text data (dynamically created as user uses the app) then show it in a FlowDocumentScrollViewer, but flow documents do a lot I don't need, I just want to display the text. Is the FlowDocument the way to go for this purpose?

Thanks
 
I think maybe a simple label or a textblock might be better then a FlowDocumentScrollViewer, but I need an object to use as a datamodel. Is there an object I can add individual text lines to and build up some kind of text object that I can bind the label to?
 
If you need more than paragraph or two of text, the flow document is really the best way to do things, specially if the text has embedded formatting within it.

But if all you need is just label or textbox, then use a label or textbox. Simply bind to a string. Strings are objects too. See line 21 and 29 of MainWindow.xaml on post #18 of the wrap panel children thread.
 
Referring back to your old topic (linked above), I would use a fragment element such as two textblocks. Setting the same parameters as described on your other topic. You could make use of the Auto property if you add in a stack panel and set your child elements to be aligned vertical or horizontal, or if each block of text contains the same amount of chars (roughly), you could manually size them instead without any stack panel, providing you are not using lots of them. You could do it either-way, as it really sounds like preference to me.
 
You know it never occured to me to use a string to store the text, it sounds strange saying that, but I'm realizing I basically just want to store a big string so using a string is fine.

Thanks for the help, I think I've got this now.
 
Also recall that a view-model is different from your actual model. The model maybe composed of many different pieces, but the view model just presents a single piece. For example:
C#:
class Person
{
    public string FirstName { get; set; }
    public string MiddleName { get; set; }
    public string LastName { get; set; }
}

class PersonViewModel
{
    Person _person;
    
    public string DisplayName
        => $"{_person.FirstName} {_person.MiddleName[0]}. {_person.LastName}";
        
    public PersonViewModel(Person person)
        => _person = person;
}
 
Back
Top Bottom