代码之家  ›  专栏  ›  技术社区  ›  Anders Rune Jensen

WPF:在网格中更改行时获取System.Windows.Data错误

  •  0
  • Anders Rune Jensen  · 技术社区  · 15 年前

    我有一个网格,我需要根据窗口的大小动态调整列数。

    我发现的唯一可行方法是使用:

    FrameworkElementFactory fGrid = new FrameworkElementFactory
      (typeof(System.Windows.Controls.Primitives.UniformGrid));
    
    fGrid.SetValue(System.Windows.Controls.Primitives.UniformGrid.ColumnsProperty, columns);
    listbox.ItemsPanel = new ItemsPanelTemplate(fGrid);
    

    在我的列表框中\u SizeChanged事件处理程序。不幸的是,它给出了以下(无害的)错误。对于如何动态地改变它,有什么更好的想法吗?

    System.Windows.Data错误:4:无法 AncestorType='System.Windows.Controls.ItemsControl', BindingExpression:Path=HorizontalContentAlignment; “ListViewItem”(名称=“”);目标 财产是 “HorizontalContentAlignment”(类型

    1 回复  |  直到 15 年前
        1
  •  1
  •   itowlson    15 年前

    数据绑定UniformGrid.Columns属性:

    <ListBox>
      <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
          <UniformGrid Rows="10" Columns="{Binding ColumnCount}" />
        </ItemsPanelTemplate>
      </ListBox.ItemsPanel>
    </ListBox>