xaml - Windows Phone : RelativeSource Mode=FindAncestor, AncestorType:无法解析符号 AncestorType

标签 xaml binding windows-phone

我正在模板化一个列表框。我喜欢仅在选择该项目时才显示路径。

数据模板:

<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/

相关文章:

c# - 如何将 ItemsControl(在网格外)绑定(bind)到网格?

c# - Windows Phone 8 中的弹出窗口

c# - 引用未编译的 c# 类

windows-runtime - 将图像添加到 MapControl 的有效/正确方法 - Windows Phone 8.1

debugging - Windows Phone 8.1 设备 (Lumia 930) 和 VS2013 调试仅适用于禁用 WiFi

c# - 是否可以将第一个字母变大并使其余文本围绕它对齐

c# - 当用户在c#中单击它时获取图像的来源

WPF GetIsInDesignMode 从转换器内部

binding - 如何绑定(bind)到 ItemsPanel 中的网格?

api - Windows Phone 应用程序中的捐赠