0

我是 Windows Phone 开发的新手。我有一个网格,其中包含一个图像。当我点击网格(图像的父级)时,我需要使图像可见,并在我第二次点击时折叠。

我的设计如下

<Grid x:Name="gridThriller" HorizontalAlignment="Left" Height="172" Margin="33,85,0,0" VerticalAlignment="Top" Width="123"  Background="Transparent" Tap="selectThiller" >
            <Image Source="/Images/right.png" HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="None"  />
        </Grid>
        <Grid x:Name="gridAction" HorizontalAlignment="Left" Height="172" Margin="186,85,0,0" VerticalAlignment="Top" Width="123"  Background="Transparent" Tap="selectThiller">
            <Image Source="/Images/right.png"  HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="None"/>
        </Grid>
        <Grid x:Name="gridHorror" HorizontalAlignment="Left" Height="172" Margin="340,85,0,0" VerticalAlignment="Top" Width="123"  Background="Transparent" Tap="selectThiller">
            <Image Source="/Images/right.png"  HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="None"/>
        </Grid>
        <Grid x:Name="gridSciFi" HorizontalAlignment="Left" Height="172" Margin="33,283,0,0" VerticalAlignment="Top" Width="123"  Background="Transparent" Tap="selectThiller">
            <Image Source="/Images/right.png"  HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="None"/>
        </Grid>
        <Grid x:Name="gridRomantic" HorizontalAlignment="Left" Height="172" Margin="186,283,0,0" VerticalAlignment="Top" Width="123"  Background="Transparent" Tap="selectThiller">
            <Image Source="/Images/right.png" HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="None"/>
        </Grid>
        <Grid x:Name="gridComedy" HorizontalAlignment="Left" Height="172" Margin="340,283,0,0" VerticalAlignment="Top" Width="123"  Background="Transparent" Tap="selectThiller">
            <Image Source="/Images/right.png"  HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="None"/>
        </Grid>
        <Grid x:Name="gridDrama" HorizontalAlignment="Left" Height="172" Margin="33,481,0,0" VerticalAlignment="Top" Width="123"  Background="Transparent" Tap="selectThiller">
            <Image Source="/Images/right.png"  HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="None"/>
        </Grid>
        <Grid x:Name="gridFantacy" HorizontalAlignment="Left" Height="172" Margin="186,481,0,0" VerticalAlignment="Top" Width="123"  Background="Transparent" Tap="selectThiller">
            <Image Source="/Images/right.png"  HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="None"/>
        </Grid>
        <Grid x:Name="gridAnimated" HorizontalAlignment="Left" Height="172" Margin="340,481,0,0" VerticalAlignment="Top" Width="123"  Background="Transparent" Tap="selectThiller">
            <Image Source="/Images/right.png"   HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="None"/>
        </Grid>

如何解决这个问题呢?

4

1 回答 1

0

好吧,看起来您的所有点击事件都指向相同的方法,所以这是一个好的第一次开始。如果你想继续沿着这条路走下去,那么我要做的就是以下。

在您的点击事件中

        foreach(Image item in (sender as Grid).Children)
        {
            if(item.Visibility == Visibility.Visible)
                item.Visibility = Visibility.Collapsed;
            else
                item.Visibility = Visibility.Visible;
        }

注意#如果您在除图像以外的网格元素中添加任何其他内容,则会爆炸。如果您需要添加其他内容,则需要在此之上添加单独的逻辑以清除图像。

于 2013-05-02T12:34:08.160 回答