WPF 鼠标悬停在StackPanel上时,出现两个按钮,StackPanel里面有一个照片,两个按钮,两个按钮都居中,照片一直显示,两个按钮鼠标悬停时显示,并且能够点击触发View Model端命令,使用触发器 实现此效果
时间: 2024-02-06 11:11:48
浏览: 129
可以使用以下XAML代码实现该效果:
```xml
<StackPanel Width="200" Height="200" Background="LightGray">
<Image Source="yourImageSource" Stretch="Uniform" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"
VerticalAlignment="Center" Visibility="Hidden">
<Button Content="Button1" Margin="5" Command="{Binding Button1Command}" />
<Button Content="Button2" Margin="5" Command="{Binding Button2Command}" />
</StackPanel>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
```