本文介绍了WindowsPhone:RelativeSource 模式=FindAncestor,AncestorType:无法解析 SymbolAncestorType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个列表框.我喜欢仅在项目被选中时才显示路径.

I'm templating a listbox. I like to show a path only if the item is selected.

数据模板:

<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 有问题.在设计器中声明:无法解析符号祖先类型.

Apparantly there is something wrong with my XAML. In the designer is states : Cannot resolve symbol ancestor type.

推荐答案

Windows Phone 不支持 AncestorType.

AncestorType is not supported on Windows Phone.

<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 中进行一些更改并完成!

Make some changes in your BooleanToVisibilityConverter and done!

这篇关于WindowsPhone:RelativeSource 模式=FindAncestor,AncestorType:无法解析 SymbolAncestorType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 13:59