Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In xaml
this works:
<TextBlock HorizontalAlignment="Right">
<Run Text="{Binding ElementName=lb, Path=SelectedItems.Count, Mode=OneWay}"/>
<Run Text="/"/>
<Run Text="{Binding ElementName=lb, Path=Items.Count, Mode=OneWay}"/>
<Run Text=" excluded"/>
</TextBlock>
Can I bind these to properties in ViewModel?
Not that hard but it took a while to figure out! I've to extend a ListBox
with two DependencyProperty
, Total and Selected. In OnSelectionChanged
I've to set the Selected = SelectedItems.Count
and in OnItemsChanged
I've to set Total = Items.Count
. Those Total and Selected can be bound to ViewModel's property.