Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ItemsControl与ObservableCollection绑定中的WPF空行_C#_Wpf_Datagrid - Fatal编程技术网

C# ItemsControl与ObservableCollection绑定中的WPF空行

C# ItemsControl与ObservableCollection绑定中的WPF空行,c#,wpf,datagrid,C#,Wpf,Datagrid,我将ItemsControl绑定到ObservableCollection,一切正常,除非ObservableCollection为空,ItemsControl将显示一个空行 <ItemsControl Visibility="Visible" ItemsSource="{Binding ocItemsinInvoice,Mode=TwoWay}" x:Name="test" Margin="10,-32,0,207" Width="412" HorizontalAlignment

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

如何删除它?

公共ObservableCollection BindeObservableCollection
public ObservableCollection<object> bindedObservableCollection
{
    get{
        ObservableCollection<object> newlist = new ObservableCollection<object>(yourObservableCollection);
        return newlist;
    }
}
{ 得到{ ObservableCollection newlist=新的ObservableCollection(您的ObservableCollection); 返回newlist; } }

当绑定到一个DATAGRID的一部分时,我发现了这个问题,我发现把它转换到一个新的相同类型的列表中,删除了空白编辑器的记录,这是DATAGRID的一部分。< /P>邮政编码,用于您的代码> ITESsReals< /Cord>模板。您确定集合不包含项吗?我发现您的xaml代码中没有问题,我使用虚拟集合对其进行了测试,没有显示任何内容。我确定,在加载的页面中,我从OCItemsInVoice初始化了新实例,当我添加新项时,将其添加到OCItemsInVoice,您所说的空行到底是什么意思?没有显示内容的按钮?请尝试单向绑定
ItemsSource=“{binding ocItemsinInvoice,Mode=OneWay}”