2

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

数据模板:

<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 有问题。在设计器中是状态:无法解析符号祖先类型。

4

1 回答 1

5

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

于 2013-03-06T13:22:04.827 回答