Is there an ItemsControl equivalent for text content?

孤人 提交于 2019-12-03 14:31:46

What you are looking for is possible, but requires significant amount of coding. Fortunately, Vincent Van Den Berghe posted a nice article on the MSDN describing how to Create Flexible UIs With Flow Documents And Data Binding , including the code!

Instead of using a FlowDocument, you can use an ItemsControl and change the panel used to display items to a WrapPanel. This will allow you use the ItemsControl as you want, but change its display semantics to a WrapPanel (which I believe functions like a FlowDocument. You'd do it something like this:

<ItemsControl>
    <ItemsControl.ItemsPanelTemplate>
        <WrapPanel />
    </ItemsControl.ItemsPanelTemplate>
</ItemsControl>

You can set any properties on the inner WrapPanel as you desire.

I think you are looking for the List element: http://msdn.microsoft.com/en-us/library/system.windows.documents.list.aspx

Bubblewrap points out a few more details. You'd likely bind to the ListItems property and need to use a ValueConverter to convert your source list to a list of type ListItemsCollection.

Bubblewrap points out that this is readonly and that the ListItemsCollection has an internal constructor. So...

I think what you'd have to do is this:

<ContentControl Content="{Binding TheArrayOfText, Converter={StaticResource StringsToListConverter}" />

This is pretty unfortunate, but I think it would work. You'd have to write a converter to create a new List object and call .Add( on each item.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!