How to Display ObservableCollection in a UserControl

后端 未结 4 1432
滥情空心
滥情空心 2021-01-15 13:48

I\'m new to WPF and I\'ve found some similar questions but can\'t quite figure out the last part. I have a ViewModel with an ObservableCollection that contains error messag

4条回答
  •  再見小時候
    2021-01-15 14:22

    May be usefull to generate FlowDocument and show this document in FlowDocumentReader. Try to start from this article: Flow Document Overview.

    Example of generation:

        void ShowErrors(FlowDocumentReader reader, Exception[] errors) {
            FlowDocument doc = new FlowDocument();
            foreach (var e in errors) {
                doc.Blocks.Add(new Paragraph(new Run(e.GetType().Name)) {
                    Style = (Style)this.FindResource("header")
                });
                doc.Blocks.Add(new Paragraph(new Run(e.Message)) {
                    Style = (Style)this.FindResource("text")
                });
            }
            reader.Document = doc;
        }
    

    In this example I have added some styles for text in flowdocument. PLease look at XAML:

    
    
        
        
    
    
    
    

    Result:

    enter image description here

提交回复
热议问题