假设图一是imgShow1图二是imgShow2,checkbox是chbSwitch 在chbSwitch的checked事件中imgShow1设置可见,imgShow2设置不可见,然后在chbSwitch的unchecked事件做相反设置
还有一个办法,imgshow2默认一直显示,放在底层,imgshow1覆盖在imgshow2上面,并把imgshow1的可见属性和checkbox的checked绑定起来
老哥,看不懂。。。。虽然好像是那么实现的
@混沌奇迹: img1是打开状态,img2是闭合状态
<CheckBox Content="CheckBox" HorizontalAlignment="Left" Margin="121,200,0,0" VerticalAlignment="Top" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"/> <Image x:Name="img2" HorizontalAlignment="Left" Height="100" Margin="111,76,0,0" VerticalAlignment="Top" Width="100" Source="pic/2.png"/> <Image x:Name="img1" HorizontalAlignment="Left" Height="100" Margin="111,76,0,0" VerticalAlignment="Top" Width="100" Source="pic/1.png"/>
private void CheckBox_Checked(object sender, RoutedEventArgs e) { img1.Visibility = Visibility.Hidden; img2.Visibility = Visibility.Visible; } private void CheckBox_Unchecked(object sender, RoutedEventArgs e) { img1.Visibility = Visibility.Visible; img2.Visibility = Visibility.Hidden; }