我有一个方形堆栈面板,里面有 3 个按钮。我希望它在选择按钮时变成圆形。
我通过使用矩形作为视觉画笔来实现这一点,然后从后面的代码中为矩形的 radiusX radiusY 设置动画。到目前为止它有效。
<Grid>
<Rectangle x:Name="Mask" Width="300" Height="300" Fill="White" RadiusX="0" RadiusY="0"/>
<StackPanel
Width="{Binding Path=Width, ElementName=Mask}"
Height="{Binding Path=Width, ElementName=Mask}"
>
<StackPanel.OpacityMask>
<VisualBrush Visual="{Binding ElementName=Mask}" />
</StackPanel.OpacityMask>
<Button x:Name="BlueButton" Width="{Binding Path=Width, ElementName=Mask}"
Background="Blue" Height="100">content</Button>
<Button x:Name="GreenButton" Width="{Binding Path=Width, ElementName=Mask}"
Background="Green" Height="100">content</Button>
<Button x:Name="WhiteButton" Width="{Binding Path=Width, ElementName=Mask}"
Background="White" Height="100">content</Button>
</Grid>
关于后面的代码:
Mask.BeginAnimation(Rectangle.RadiusXProperty, new DoubleAnimation(Mask.ActualWidth/2, AnimTime));
Mask.BeginAnimation(Rectangle.RadiusYProperty, new DoubleAnimation(Mask.ActualWidth / 2, AnimTime));
现在的问题是,我想在点击它时更改包的内容。我希望选定的按钮占据左侧的一列,其余的消失。类似的东西(选择蓝色时)
我为蓝色按钮的宽度和高度设置动画,但是..这就是我得到的..
我怎样才能防止这种变形,让蓝色的东西被矩形遮住?它显然没有被它掩盖(矩形用图片中的黑色圆圈线标记)