Search code examples
wpfxamllistcollectionview

Bind to ICollectionView.Count property in XAML


I'm trying to bind a text box to the count of a filtered, collection view in XAML. It doesn't generate any errors but it also doesn't produce any output. Does anyone know how to do this?

Here's are some snippets of my XAML:

<Window.Resources>
  <CollectionViewSource x:Key="MyView" Source="{Binding MyBinding}" Filter="MyFilter" />
</Window.Resources>

...

<TextBlock>
  <TextBlock.Text>
    <Binding Source="{StaticResource MyView}" Path="View.Count"  
      StringFormat="{}Count: {0:D}" />
  </TextBlock.Text>
</TextBlock>

Basically, I'm trying to display the count of filtered items in the List.


Solution

  • You don't need the "View." in the path. it should just be:

    Path="Count"