WPF WrapPanel/StackPanel with DataTemplate?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-14 09:36:08

问题


What must I do to use a DataTemplate in a WrapPanel or StackPanel?

On a ListBox its so easy but i cant find a way to do it on a Panel...

Edit: What i want is a ListBox that places the items like a WrapPanel.


回答1:


If I understand you correctly, you can use the ItemsPanel property of your container. I used something similar to make my ItemsControl layout using a horizontal StackPanel:

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal" />
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

So, more specifically for your case:

<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel />
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>



回答2:


There isn't a DataTemplate property for those panels..

You can however use a ControlTemplate for these panels, and set these in the Template property of these panels...

HTH



来源:https://stackoverflow.com/questions/666637/wpf-wrappanel-stackpanel-with-datatemplate

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