简体   繁体   English

绑定到GridView.Items.Count在UWP中始终返回0

[英]Binding to GridView.Items.Count always return 0 in UWP

I have a gridview in UWP and work fine 我在UWP中有gridview并且工作正常

 <GridView x:Name="my_gridview" ItemsSource="{Binding CollectionItem, Mode=TwoWay}"/>

And have a textblock for show the count of CollectionItem 并有一个文本块来显示CollectionItem的计数

 <TextBlock Text="{Binding ElementName=my_gridview, Path=Items.Count, RelativeSource={RelativeSource Self}}"/>

Problem: the textblock always show 0 even we have many items in my gridview! 问题:即使我们的gridview中有很多项目,文本块也始终显示0!

更好地直接绑定到源集合:

<TextBlock Text="{Binding CollectionItem.Count}" />

您同时设置ElementNameRelativeSource (这是伪造的),后者可能会覆盖前者或导致冲突错误,请检查“输出”窗口,然后将出现绑定错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM