I have a ObservableCollection<Sportisti>
that starts out with 0 elements (but is initialized to a new object at the creation of the window). I wanted to bind the Count
property to a TextBox
. Unfortunately, this causes my application to crash whenever I try to open the window in question.
Now, since I have a ListView
on the same page, successfully showing the elements of the collection in question, I thought I could simply extract the number of rows from there, but that also lead to a crash.
<TextBox Text="{Binding ElementName=lvTabela, Path=Items.Count}"
Grid.Row="4" Grid.Column="1" Margin="0,3,60,3"
DockPanel.Dock="Top" IsReadOnly="True" />
Note that in the .xaml file I can see the content of the TextBox is 0.
Any idea why this is happening?
My mistake, I forgot to add the Mode=OneWay
to the binding. The problem was that, even though the TextBox wasn't editable, the system recognized this as a potential way of changing the ListView.ItemCount attribute, which is read-only.
My suggestion: Initialize your collection to empty objects in your code when the the list initializes. This may help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With