开发者

WPF DispatcherTimer on Modalless window

I have a wpf progress window defined as following:

<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>

And a code behind file as follows:

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);
        }

    }

You can see that I try to start a progressBar animation in two ways: -using EventTrigger, on ProgressBar.Loaded -from code behind, explicitely

The problem is - neither works.

Note - I开发者_Python百科 need to open this window and start animation as modalless window, so ShowDialog() is not na option. Also, I tried using DispatcherTimer, but it somehow doesn't work, niether the this.Dispatcher.Invoke() while using System.Timers.Timer class.

I'm calling the DisplayWindow() method from the main app window.

What am I missing?

Thanks in advance


I couldn't reproduce your problem, your XAML animation is working just fine!, try to copy your XAML code to a new project without the code-behind. I tried that and worked just fine :D

WPF DispatcherTimer on Modalless window


I found out what the problem was - i called NewWindow.Show(), and then continued with some high CPU computing, assuming that the new window will be on separate thread if not called with ShowDialog().

I fixed it using BackgroundWorker!

Thanks for help anyways!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜