private void Window_Loaded(object sender, RoutedEventArgs e) { // set window position to middle of parent window Application curApp = Application.Current; Window mainWindow = curApp.MainWindow; this.Left = mainWindow.Left + (mainWindow.Width - this.ActualWidth) / 2; this.Top = mainWindow.Top + (mainWindow.Height - this.ActualHeight) / 2; //start backgroundworker bw_scannbluetooth.RunWorkerAsync(); Duration duration = new Duration(TimeSpan.FromSeconds(13)); System.Windows.Media.Animation.DoubleAnimation doubleanimation = new System.Windows.Media.Animation.DoubleAnimation(200.0, duration); Progressbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation); }
private void InitializePresetScriptCombobox() { LoadingOverlay.Visibility = Visibility.Visible; presetScriptItems = new List<PresetScript>(); Progressbar.Value = 0; worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += (obj, e) => { try { //string baseDir = AppDomain.CurrentDomain.BaseDirectory; Directory.CreateDirectory("presets"); string[] fileList = Directory.GetFiles("presets"); int count = fileList.Length; string filename; for (int i = 0; i < count; i++) { filename = Path.GetFileNameWithoutExtension(fileList[i]); presetScriptItems.Add( new PresetScript( filename, GetContent(fileList[i]))); double percent = ((i + 1) * 100) / count; worker.ReportProgress((int)percent); Thread.Sleep(500); } } catch { throw new Exception(); } }; worker.ProgressChanged += (obj, e) => { //Progressbar.Value = e.ProgressPercentage; DoubleAnimation animation = new DoubleAnimation(e.ProgressPercentage, TimeSpan.FromMilliseconds(500)); Progressbar.BeginAnimation(ProgressBar.ValueProperty, animation); }; worker.RunWorkerCompleted += (obj, e) => { PresetScriptCombobox.ItemsSource = presetScriptItems; PresetScriptCombobox.DisplayMemberPath = "Name"; PresetScriptCombobox.SelectedValuePath = "Script"; PresetScriptCombobox.SelectionChanged += PresetScriptCombobox_SelectionChanged; if (savingNewScript) { PresetScriptCombobox.SelectedItem = presetScriptItems.FirstOrDefault(x => x.Name == savingNewScriptName); savingNewScript = false; } else { PresetScriptCombobox.SelectedIndex = -1; } LoadingOverlay.Visibility = Visibility.Collapsed; }; worker.RunWorkerAsync(); }