【发布时间】:2026-01-02 15:05:01
【问题描述】:
在我的应用程序主窗口中:
public MainWindow() {
InitializeComponent();
Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => {
var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
var transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
var corner = transform.Transform(new Point(workingArea.Right, workingArea.Bottom));
this.Left = corner.X - this.ActualWidth - 100;
this.Top = corner.Y - this.ActualHeight;
}));
NotificationWindow nw1 = new NotificationWindow();
spNotifiers.Children.Add(nw1);
}
我的通知器如下所示:
<UserControl
x:Class="NotificationWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="Transparent" MouseEnter="UserControl_MouseEnter">
<Grid RenderTransformOrigin="0,1">
<Border BorderThickness="1" Background="Beige" BorderBrush="Black" CornerRadius="10">
<StackPanel Margin="20">
<TextBlock TextWrapping="Wrap" Margin="5">
<Bold>Besked fra podio</Bold><LineBreak /><LineBreak />
Her skal der være en podio notification!
</TextBlock>
<CheckBox Content="Check check" Margin="5 5 0 5" />
<Button Content="Klik på mig" HorizontalAlignment="Center" />
</StackPanel>
</Border>
<!-- Animation -->
<Grid.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard x:Name="sbMain">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
<SplineDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
<SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
<SplineDoubleKeyFrame KeyTime="0:0:4" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
<Grid.RenderTransform>
<ScaleTransform ScaleY="1" />
</Grid.RenderTransform>
</Grid>
private void UserControl_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e) {
sbMain.Stop(); // not working
}
从通知我有一个 mouse_anter 事件,应该停止动画/故事板,但无论我尝试什么,我都无法让动画停止。
有什么想法吗?
【问题讨论】:
-
您是否再次调用了 BeginAnimation,并将第二个参数设置为 null。
-
如果我可以问,第一个参数应该是什么?
-
BeginAnimation((isVertical ? VerticalScrollProperty : HorizontalScrollProperty), null);来源:viblend.wordpress.com/2011/03/18/…