Voglio ottenere il conteggio di un oggetto ListView. Ma usa un Template, quindi, ho bisogno di usare AncestorType, ho un codice che in WPF funziona bene, ma in Windows Store Apps 8 no, perché non c'è AncestorType lì, quindi cosa posso fare invece? Come posso far funzionare questo codice in winRT?WinRT Cosa può essere invece AncestorType?
Ecco il mio codice:
<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>
ho condiviso una soluzione per RelativeSource AncestorType in UWP sopra a http://stackoverflow.com/a/43399114/303612 –