我有如下定義一個WPF進度窗口:WPF DispatcherTimer上Modalless窗口
<Window x:Class="NeoinfoXmlEditor.WPF.Forms.ProgressDisplayForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="84" Width="505" x:Name="root" WindowStartupLocation="CenterScreen">
<Grid>
<ProgressBar Height="15" x:Name="MessageProgessBar" HorizontalAlignment="Stretch" VerticalAlignment="Top" Maximum="10000" Margin="10,2,10,2" >
<ProgressBar.Triggers>
<EventTrigger RoutedEvent="ProgressBar.Loaded">
<BeginStoryboard>
<Storyboard x:Name="sb">
<DoubleAnimation Storyboard.TargetName="MessageProgessBar"
Storyboard.TargetProperty="Value"
From="0" To="10000" Duration="0:0:45"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ProgressBar.Triggers>
</ProgressBar>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="5" Text="{Binding ElementName=root, Path=Message}" />
</Grid>
</Window>
而且隱藏文件代碼如下:
public partial class ProgressDisplayForm : Window
{
public static readonly DependencyProperty MessageProperty =
DependencyProperty.Register("Message", typeof (string), typeof (ProgressDisplayForm));
public string Message
{
get { return (string) GetValue(MessageProperty); }
set { SetValue(MessageProperty, value); }
}
public ProgressDisplayForm()
{
InitializeComponent();
}
public void DisplayWindow()
{
this.Show();
this.BeginStoryboard(sb);
}
}
你可以看到,我試圖啓動一個進度動畫在兩個方面: - 使用EventTrigger,在ProgressBar.Loaded - 從後面的代碼,明確地
的問題是 - 沒有工作。
注 - 我需要打開此窗口並以無模式窗口啓動動畫,因此ShowDialog()不是na選項。此外,我嘗試使用DispatcherTimer,但它以某種方式不起作用,而不是在使用System.Timers.Timer類時this.Dispatcher.Invoke()。
我從主應用程序窗口調用DisplayWindow()方法。
我錯過了什麼?
在此先感謝
嗯。這對我來說可以。我把你的XAML粘貼到新的WPF項目中,並在啓動後生成動畫。 – 2011-04-06 11:53:31