【问题标题】:WPF Empty Row in ItemsControl Binding with ObservableCollection与 ObservableCollection 绑定的 ItemsControl 中的 WPF 空行
【发布时间】:2013-11-03 09:44:14
【问题描述】:

我有 ItemsControl 绑定到 ObservableCollection,一切正常,除非 ObservableCollection 为空,ItemsControl 将显示一个空行!

<ItemsControl  Visibility="Visible" ItemsSource="{Binding ocItemsinInvoice,Mode=TwoWay}" 
  x:Name="test" Margin="10,-32,0,207" Width="412" HorizontalAlignment="Left">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="1" VerticalAlignment="Top" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>

    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button x:Name="btnOpenInvoice" Style="{StaticResource OpenInvoicesButton}" 
              FontSize="12" Width="300" Height="60" Foreground="#ff252526">
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="{Binding Item.ItemName}" 
                       HorizontalAlignment="Center" VerticalAlignment="Center" />
                </StackPanel>
            </Button>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

我怎样才能删除它?

【问题讨论】:

  • ItemsControl 模板的邮政编码在这里。
  • 您确定该集合不包含任何项目吗?我在您的 xaml 代码中没有发现任何问题,我使用虚拟集合对其进行了测试,没有显示任何内容。
  • 我确定,在加载的页面中,我从 ocItemsinInvoice 初始化了新实例,当我添加新项目时,将其添加到 ocItemsinInvoice
  • 空行是什么意思?显示没有内容的按钮?
  • 尝试一种方式绑定ItemsSource="{Binding ocItemsinInvoice, Mode=OneWay}"

标签: c# wpf datagrid


【解决方案1】:
public ObservableCollection<object> bindedObservableCollection
{
    get{
        ObservableCollection<object> newlist = new ObservableCollection<object>(yourObservableCollection);
        return newlist;
    }
}

我在绑定到属于数据网格的列表时遇到了这个问题,我发现将其转换为相同类型的新列表会删除属于数据网格的空白编辑器记录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-30
    • 2015-01-26
    • 1970-01-01
    • 1970-01-01
    • 2018-09-30
    • 1970-01-01
    • 2012-07-04
    • 1970-01-01
    相关资源
    最近更新 更多