我正在模板化一个列表框。我喜欢仅在选择该项目时才显示路径。
数据模板:
<DataTemplate x:Key="itplPlayerOfTheDay">
<Grid>
...
<Grid Width="50" Height="50" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,5,5,0">
<Path Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor , AncestorType={ListBoxItem}}, Path=IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" Data="M32.5569,7.54591 C32.3883,13.1553 31.3485,16.9274z" Stretch="Uniform" Stroke="Black" >
</Path>
</Grid>
...
</Grid>
</DataTemplate>
显然我的 XAML 有问题。在设计器中状态为:无法解析符号祖先类型。
最佳答案
Windows Phone 不支持 AncestorType。
<DataTemplate x:Key="itplPlayerOfTheDay">
<Grid>
...
<Grid Width="50" Height="50" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,5,5,0">
<Path Visibility="{Binding ElementName=yourListBoxName, Path=SelectedItem, Converter={StaticResource BooleanToVisibilityConverter}}" Data="M32.5569,7.54591 C32.3883,13.1553 31.3485,16.9274z" Stretch="Uniform" Stroke="Black" >
</Path>
</Grid>
...
</Grid>
</DataTemplate>
在 BooleanToVisibilityConverter 中进行一些更改并完成!
关于xaml - Windows Phone : RelativeSource Mode=FindAncestor, AncestorType:无法解析符号 AncestorType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15233072/