0

我有 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>

我怎样才能删除它?

4

1 回答 1

0
public ObservableCollection<object> bindedObservableCollection
{
    get{
        ObservableCollection<object> newlist = new ObservableCollection<object>(yourObservableCollection);
        return newlist;
    }
}

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

于 2019-08-07T23:51:29.203 回答