如何顯示擴展器內容的itemsCount

[英]How can I display an itemsCount for Expander content


I have spent wayyyy too much time on this, so if someone can help point me in the right direction, I would be very appreciative.

我花了太多時間在這上面,所以如果有人可以幫我指出正確的方向,我會非常感激。

I have an Expander with a ListBox in it. I have bound the ListBox to a List ie FilteredProjects. I would like the Header of the expander to reflect the number of items in the displayed list. I did implement INotifyPropertyChanged for ProjectsCount, and the ItemsSource for the ListBox updates just fine. Thanks in advance for your time.

我有一個帶有ListBox的擴展器。我已將ListBox綁定到List,即FilteredProjects。我希望擴展器的Header能夠反映顯示列表中的項目數。我確實為ProjectsCount實現了INotifyPropertyChanged,而ListBox的ItemsSource更新得很好。在此先感謝您的時間。

        <Expander>
            <Expander.HeaderTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Projects" />
                        <Border CornerRadius="4" Padding="0" BorderThickness="1" BorderBrush="Black" Background="#FF545F42" Margin="1,0,0,0" >
                            <Label Content="{Binding Path=ProjectsCount, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource filter}}" Padding="0" FontSize="8" FontStyle="Italic"></Label>
                        </Border>
                    </StackPanel>
                </DataTemplate>
            </Expander.HeaderTemplate>
            <ListBox x:Name="ProjectsFilterListView" Opacity="1" ItemsSource="{Binding FilteredProjects}"  >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <CheckBox IsChecked="{Binding IsSelected}"  Content="{Binding ItemName}" Margin="10,10,0,10"></CheckBox>
                    </DataTemplate>
                    </ListBox.ItemTemplate>
            </ListBox>
        </Expander>

1 个解决方案

#1


1  

You could just get the Item Count directly from the ListBox

您可以直接從ListBox獲取項目計數

<Label Content="{Binding Path=Items.Count, ElementName=ProjectsFilterListView}" />

Here is an example of it working, I replaced Label for TextBlock so I could use StringFormat to add "Items:" text before the number as I am not sure what your Converter is doing

這是一個工作的例子,我替換了TextBlock的Label,所以我可以使用StringFormat在數字之前添加“Items:”文本,因為我不確定你的Converter在做什么

<StackPanel Orientation="Horizontal">
    <TextBlock Text="Projects" />
    <Border CornerRadius="4" Padding="0" BorderThickness="1" BorderBrush="Black" Background="Red" Margin="1,0,0,0" >
        <TextBlock Text="{Binding Path=Items.Count, ElementName=ProjectsFilterListView, StringFormat={} Items: {0}}" Padding="0" FontSize="10" FontStyle="Italic" Foreground="Black"/>
    </Border>
</StackPanel>

Result:

結果:

enter image description here


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/04/01/532b84b50a1677f83b36b80edf54d727.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com