【问题标题】:Data Binding UserControls to WrapPanel将用户控件数据绑定到 WrapPanel
【发布时间】:2013-08-16 12:34:14
【问题描述】:

我正在尝试研究如何将用户控件列表数据绑定到 WrapPanel,但我没有太多的运气搜索。

我对 WPF 很陌生(来自 WinForms),目前我在运行时将 UserControls 添加为子项。据我所知,WrapPanel 不支持数据绑定,是否有任何解决方案。

【问题讨论】:

    标签: c# wpf data-binding wrappanel


    【解决方案1】:

    试试这样的:

    <ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding YourSource}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel IsItemsHost="True" />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        ...
    </ListBox>
    

    如果你不需要选择的东西,你可以尝试使用 ItemsControl。

    <ItemsControl ItemsControlScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding YourSource}">
         <ItemsControl.ItemsPanel>
               <ItemsPanelTemplate>
                       <WrapPanel IsItemsHost="True" />    
               </ItemsPanelTemplate>
         </ItemsControl.ItemsPanel>
         ...
    </ItemsControl>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-29
      • 2013-12-30
      • 2014-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-28
      • 2014-11-01
      相关资源
      最近更新 更多