我刚接触Windows手机开发。我有一个网格,其中包含一个图像。当我点击网格(图像的父级)时,我需要使图像可见,而当我第二次点击时,我需要折叠。
我的设计如下
<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>
如何解决这个问题?
答案 0 :(得分:0)
好吧,看起来你有一个tap事件,所有人都指向同一个方法,这样就可以了。如果你想继续沿着这条路走下去,我会做的就是以下几点。
在点按活动中
foreach(Image item in (sender as Grid).Children)
{
if(item.Visibility == Visibility.Visible)
item.Visibility = Visibility.Collapsed;
else
item.Visibility = Visibility.Visible;
}
注意#如果你将其他任何东西放在除了图像之外的那些网格元素中,这将会爆炸。如果你需要添加其他东西,那么你需要在其上面添加单独的逻辑来清除图像。