Tôi muốn nhận số lượng mục ListView. Nhưng nó sử dụng một mẫu, do đó, tôi cần phải sử dụng AncestorType, tôi có một mã mà trong WPF hoạt động tốt, nhưng trong Windows Store Apps 8 không, bởi vì không có AncestorType ở đó, vì vậy tôi có thể làm gì? Làm thế nào tôi có thể làm cho mã này hoạt động trong winRT?WinRT Điều gì có thể thay thế AncestorType?
Đây là mã của tôi:
<ListView ItemsSource="{Binding Users}">
<ListView.Style>
<Style TargetType="ListView">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border BorderThickness="1" BorderBrush="LightGray">
<StackPanel>
<ScrollViewer>
<ItemsPresenter />
</ScrollViewer>
<TextBlock Margin="0,4" FontWeight="Bold">
<Run Text="Count: "/>
<Run Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListView}}, Path=Items.Count, Mode=OneWay}"/>
</TextBlock>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
</ListView.Style>
<ListView.ItemTemplate>
<DataTemplate>
<ListViewItem IsHitTestVisible="False">
<StackPanel>
<facebookControls:ProfilePicture Height="74" Width="74" ProfileId="{Binding FacebookId}" />
<TextBlock Text="{Binding UserName}" FontSize="18" HorizontalAlignment="Center" />
</StackPanel>
</ListViewItem>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
tôi chia sẻ một giải pháp cho RelativeSource AncestorType trong UWP qua tại http://stackoverflow.com/a/43399114/303612 –