我是WPF的初學者。 我想在每個打勾上顯示我的表格。 但它只顯示一次。 當我調試這個,它在計時器滴答事件中打this.topmost=true
,但是 它沒有顯示窗口。 我不確定這段代碼有什麼問題。wpf中的動畫
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 0, 2, 0);
timer.Tick += tick;
timer.Start();
}
private void tick(object sender, EventArgs e)
{
this.Topmost = true;//display the form
this.Show();
}
}
<Border BorderThickness="1" Background="Beige" BorderBrush="Black" CornerRadius="10">
<StackPanel Margin="20">
<CheckBox Content="Checkable" Margin="5 5 0 5" />
<Button Content="Clickable" HorizontalAlignment="Center" />
</StackPanel>
</Border>
<!-- Animation -->
<Grid.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
<SplineDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
<SplineDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
<SplineDoubleKeyFrame KeyTime="0:0:8" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
我對你想要做的事情有點困惑。表單正在初始化並在InitializeComponent方法中顯示。你所有的定時器正在做的是使它成爲最頂層的窗口。它現在已經可見了。 –
一個完全無關的建議(因爲你提到你是WPF的新手),而不是使用'新TimeSpan(0,0,0,2,0)',使用'TimeSpan.FromSeconds(2)'。它使代碼更易於閱讀:) –