是否可以在同一表单的其他地方的单独标签中添加组项的项计数?



我正在编写一个包含 DataGrid (c# WPF( 的新应用程序,并且我在部分上方显示了 itemcount,并希望该计数也显示在标签中。 我该怎么做?

链接到数据网格的照片

我试过了 <Label Width="30" Height="30" Content="{Binding ElementName=dataGrid1, Path=Items.Count}" />

但它显示整个行计数,而不仅仅是"已安装"计数。

    <Style x:Key="groupheaderstyle" TargetType="{x:Type GroupItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}">
                    <Expander x:Name="exp" IsExpanded="True" Background="LightBlue" Foreground="Black">
                        <Expander.Header>
                            <DockPanel>
                                <TextBlock Text="{Binding Path=Name}" />
                                <TextBlock Text="{Binding Path=ItemCount}" Margin="8,0,4,0"/>
                            </DockPanel>
                        </Expander.Header>
                        <ItemsPresenter />
                    </Expander>
                </ControlTemplate>
            </Setter.Value>
        </Setter>[Link to the datagrid photo][1]

在这种情况下,查看您的 ItemsSource 的结构会有所帮助。

我想这应该可以解决问题。

// For first group
<Label Content="{Binding Path=ItemsSource.Groups[0].ItemCount, ElementName=dataGrid1}" />
// For second group
<Label Content="{Binding Path=ItemsSource.Groups[1].ItemCount, ElementName=dataGrid1}" />

最新更新