Esempio n. 1
0
        private void MakeFive(object sender, RoutedEventArgs e)
        {
            sbar.Items.Clear();
            TextBlock txtb = new TextBlock();
            txtb.Text = "ProgressBar";
            sbar.Items.Add(txtb);
            Button btn = new Button();
            btn.Height = 50;
            btn.Width = 50;
            Image image = new Image();
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.UriSource = new Uri(@"pack://application:,,,/data/cat.png");
            bi.EndInit();
            image.Source = bi;
            ImageBrush imagebrush = new ImageBrush(bi);
            btn.Background = imagebrush;

            ProgressBar progbar = new ProgressBar();
            progbar.Background = imagebrush;
            progbar.Width = 150;
            progbar.Height = 15;
            Duration duration = new Duration(TimeSpan.FromMilliseconds(2000));
            DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
            doubleanimation.RepeatBehavior = new RepeatBehavior(5);
            progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
            btn.Content = progbar;
            sbar.Items.Add(btn);
         }
        public static void SetPercent(this System.Windows.Controls.ProgressBar progressBar, double percentage, double _duration)
        {
            var             duration  = TimeSpan.FromSeconds(_duration);
            DoubleAnimation animation = new DoubleAnimation(percentage, duration);

            progressBar.BeginAnimation(System.Windows.Controls.ProgressBar.ValueProperty, animation);
        }
Esempio n. 3
0
 public static void SetPercent(this System.Windows.Controls.ProgressBar progressBar, double percentage)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         DoubleAnimation animation = new DoubleAnimation(percentage, TimeSpan.FromSeconds(2))
         {
         };
         progressBar.BeginAnimation(RangeBase.ValueProperty, animation);
     });
 }
Esempio n. 4
0
        private void buttonStart_Click(object sender, RoutedEventArgs e)
        {
            buttonStart.IsEnabled = false;
            int SecondsToComplete = 30; //Program specific value

            System.Windows.Controls.ProgressBar progress = new System.Windows.Controls.ProgressBar();
            progress.IsIndeterminate = false;
            progress.Orientation     = System.Windows.Controls.Orientation.Horizontal;
            progress.Width           = 419;
            progress.Height          = 20;

            Duration        duration         = new Duration(TimeSpan.FromSeconds((SecondsToComplete * 1.35)));
            DoubleAnimation doubleAnimatiion = new DoubleAnimation(200, duration);

            StatusBar1.Items.Add(progress);

            try
            {
                TaskScheduler uiThread = TaskScheduler.FromCurrentSynchronizationContext();

                Action MainThreadDoWork = new Action(() =>
                {
                    //add thread safe code here.
                    //Confirm thread will not use GUI thread
                    System.Threading.Thread.Sleep(20000);
                });

                Action ExecuteProgressBar = new Action(() =>
                {
                    progress.BeginAnimation(System.Windows.Controls.ProgressBar.ValueProperty, doubleAnimatiion);
                });

                Action FinalThreadDoWOrk = new Action(() =>
                {
                    buttonStart.IsEnabled = true;
                    StatusBar1.Items.Remove(progress);
                });

                Task MainThreadDoWorkTask = Task.Factory.StartNew(() => MainThreadDoWork());

                Task ExecuteProgressBarTask = new Task(ExecuteProgressBar);
                ExecuteProgressBarTask.RunSynchronously();

                MainThreadDoWorkTask.ContinueWith(t => FinalThreadDoWOrk(), uiThread);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Error", ex.Message, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 5
0
 private void MakeOne(object sender, RoutedEventArgs e)
 {
    sbar.Items.Clear();
    Button btn = new Button();
    btn.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
    btn.Content = "Progress Bar";
    sbar.Items.Add(btn);
    ProgressBar progbar = new ProgressBar();
    progbar.IsIndeterminate = false;
    progbar.Orientation = Orientation.Horizontal;
    progbar.Width = 150;
    progbar.Height = 15;
    Duration duration = new Duration(TimeSpan.FromSeconds(10));
    DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
    progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
    sbar.Items.Add(progbar);
   } 
Esempio n. 6
0
 private void MakeThree(object sender, RoutedEventArgs e)
 {
   sbar.Items.Clear();
   Button btn = new Button();
   btn.Background = new LinearGradientBrush(Colors.Pink, Colors.Red, 90);
   btn.Content = "Progress Bar";
   sbar.Items.Add(btn);
   ProgressBar progbar = new ProgressBar();
   progbar.Background = Brushes.Gray;
   progbar.Foreground = Brushes.Red;
   progbar.Width = 150;
   progbar.Height = 15;
   Duration duration = new Duration(TimeSpan.FromMilliseconds(2000));
   DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
   doubleanimation.RepeatBehavior = new RepeatBehavior(3);
   progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
   sbar.Items.Add(progbar);
 }
Esempio n. 7
0
        void Delay(int before, int after, ProgressBar temp)
        {
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();
            myDoubleAnimation.From = before;
            myDoubleAnimation.To = after;
            myDoubleAnimation.Duration =  new Duration(TimeSpan.FromSeconds(0.5));

            // Apply the animation to the button's Width property.
            temp.BeginAnimation(ProgressBar.ValueProperty, myDoubleAnimation);
        }
Esempio n. 8
0
 private void MakeForever(object sender, RoutedEventArgs e)
 {
   sbar.Items.Clear();
   Button btn = new Button();
   btn.Background = new LinearGradientBrush(Colors.LightBlue,        
                                            Colors.SlateBlue, 90);
   btn.Content = "Progress Bar - Forever";
   sbar.Items.Add(btn);
   ProgressBar progbar = new ProgressBar();
   progbar.Width = 150;
   progbar.Height = 15;
   Duration duration = new Duration(TimeSpan.FromSeconds(1));
   DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
   doubleanimation.RepeatBehavior = RepeatBehavior.Forever;
   progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
   sbar.Items.Add(progbar);
  
 }
Esempio n. 9
0
        private void uploadBinary(string db, string executable)
        {
            haveBinId = false;

            WindowInteropHelper helper = new WindowInteropHelper(this);
            SubmissionWorker w = new SubmissionWorker(helper.Handle, workers.Count());
            w.DoWork += new DoWorkEventHandler(worker_DoWork);
            w.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
            w.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            w.WorkerReportsProgress = true;
            w.WorkerSupportsCancellation = false;

            RowDefinition row = new RowDefinition();
            outerGrid.RowDefinitions.Add(row);
            row.Height = new GridLength(26);
            Label l = new Label();
            l.Content = "Upload binary...";
            l.Height = 26;
            Grid.SetRow(l, outerGrid.RowDefinitions.Count() - 1);
            Grid.SetColumn(l, 0);
            outerGrid.Children.Add(l);

            ProgressBar p = new ProgressBar();
            p.Height = 26;
            p.Width = 75;
            Grid.SetRow(p, outerGrid.RowDefinitions.Count() - 1);
            Grid.SetColumn(p, 1);
            outerGrid.Children.Add(p);

            DoubleAnimation a = new DoubleAnimation(0.0, 100.0, new Duration(TimeSpan.FromSeconds(1)));
            a.RepeatBehavior = RepeatBehavior.Forever;
            a.AutoReverse = true;
            p.BeginAnimation(System.Windows.Controls.ProgressBar.ValueProperty, a);

            pbars.Add(w.id, p);
            Object[] args = { "Upload", db, executable };
            workers.Add(w.id, w);
            w.RunWorkerAsync(args);
        }
Esempio n. 10
0
        private static void ProcessTestPage(TestPage testPage, ObservableCollection<TestResult> testResults, ProgressBar testingProgress)
        {
            try
            {
                // Create page load (async)
                CQ.CreateFromUrlAsync(testPage.URL, responseSuccess =>
                {
                    var testResult = new TestResult() { URL = testPage.URL };

                    // Fix "stream close"
                    var doc = responseSuccess.Dom;

                    foreach (var element in testPage.ElementList)
                    {
                        // Check if element is supported
                        if (_checkSupportedElements && !_supportedElements.Contains(element.Name.ToLowerInvariant()))
                        {
                            testResult.Cases.Add(new TestCase(element) { Unsupported = true });
                        }
                        else
                        {
                            // Select element
                            var foundElement = doc.Select(element.Name);
                            if (foundElement != null && foundElement.Contents().Any())
                            {
                                // Found, check if meets expected value
                                var currentValue = foundElement.Contents()[0].NodeValue.Trim();

                                // Compare current value to expected
                                // Note: Empty expected values are considered valid
                                if (string.IsNullOrEmpty(element.ExpectedValue) || currentValue.Equals(element.ExpectedValue))
                                {
                                    System.Diagnostics.Debug.WriteLine("Valid");
                                }
                                else
                                {
                                    System.Diagnostics.Debug.WriteLine("Invalid, expected {0} received {1}", currentValue, element.ExpectedValue);
                                    testResult.Cases.Add(new TestCase(element) { ActualValue = currentValue });
                                }
                            }
                        }
                    }

                    // Set test icons based on results
                    testResult.Icon = new TestResultIcon(
                        testResult.Cases.Any() ? TestResultIcon.TestResultState.FAIL : TestResultIcon.TestResultState.PASS
                        );

                    // Add results (invoke main ui thread)
                    System.Windows.Application.Current.Dispatcher.Invoke(() => {
                        testResults.Add(testResult);
                        DoubleAnimation doubleanimation = new DoubleAnimation(testingProgress.Value + 100, new Duration(TimeSpan.FromSeconds(1)));
                        testingProgress.BeginAnimation(System.Windows.Controls.Primitives.RangeBase.ValueProperty, doubleanimation);
                    });

                }, responseFail =>
                {
                    // TODO
                });
            }
            catch (UriFormatException)
            {
                System.Diagnostics.Debug.WriteLine("Invalid URL");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error: {0}", e.Message);
            }
        }
Esempio n. 11
0
 public static void ChangeValue(double fromValue, double toValue, ProgressBar control)
 {
     DoubleAnimation da = new DoubleAnimation(fromValue, toValue, time);
     da.DecelerationRatio = acceleration;
     da.FillBehavior = FillBehavior.Stop;
     currentToValue = toValue;
     da.Completed += ValueChanged;
     control.BeginAnimation(ProgressBar.ValueProperty, da);
 }
Esempio n. 12
0
 void setProgressBarValue(ProgressBar progressBar, double value) {
     var duration = TimeSpan.FromMilliseconds(500);
     var animation = new DoubleAnimation(value, duration);
     progressBar.BeginAnimation(ProgressBar.ValueProperty, animation);
 }