private void InitializeComponent() { AvaloniaXamlLoader.Load(this); searchBox = this.FindControl <TextBox>("SearchBox"); resultsList = this.FindControl <ListBox>("ResultsList"); adapter = new SelectingItemsControlSelectionAdapter(resultsList); adapter.Commit += ResultCommit; searchBox.GotFocus += (_, _) => { if (searchBoxMoveToEnd) { searchBox.SelectionEnd = searchBox.SelectionStart = searchBox.Text.Length; } else { searchBox.SelectAll(); } }; searchBox.KeyDown += SearchBox_KeyDown; this.GetObservable(IsVisibleProperty).SubscribeAction(@is => { if (@is) { DispatcherTimer.RunOnce(() => { searchBox?.Focus(); }, TimeSpan.FromMilliseconds(1)); } }); }
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { DispatcherTimer.RunOnce(() => { this.FindControl <TheEnginePanel>("TheEnginePanel").Focus(); }, TimeSpan.FromMilliseconds(1)); }
private void HistoryChanged(object?sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems?[0] is IControl control) { DispatcherTimer.RunOnce(control.BringIntoView, TimeSpan.Zero); } }
public AppUI() { var blurb1 = App.TextBlock; blurb1.Text = "Open an audio file to attempt to identify it."; blurb1.TextAlignment = TextAlignment.Center; rootPan.Spacing = 10; var resultGd = App.DataGrid; resultGd.Items = new List <Recording>() { }; var openF = App.HorizontalFieldWithButton; openF.holder.HorizontalAlignment = HorizontalAlignment.Center; openF.label.Text = "Audio file:"; openF.field.IsReadOnly = true; openF.field.Width = 600; openF.button.Content = "Open File..."; openF.button.Click += async(z, zz) => { var afPath = await OpenFile(); if (!string.IsNullOrWhiteSpace(afPath)) { var tempB = blurb1.Text; openF.field.Text = afPath; var aResp = new List <LookupResponse>(); try { ((App)Application.Current).LoadingBar.IsIndeterminate = true; blurb1.Text = "Identifying audio..."; aResp = await lib.ProcessAudioFile(new Uri(afPath)); ((App)Application.Current).LoadingBar.IsIndeterminate = false; blurb1.Text = tempB; } catch (Exception e) { ((App)Application.Current).LoadingBar.IsIndeterminate = false; blurb1.Text = tempB; Console.WriteLine(e); } if (aResp.Any()) { resultGd.Items = aResp.SelectMany(zzz => { return(zzz.Results.SelectMany(zzzz => { return zzzz.Recordings; })); }).ToList(); } else { blurb1.Text = "No matches found."; DispatcherTimer.RunOnce(() => { blurb1.Text = tempB; }, new TimeSpan(0, 0, 0, 5, 0)); } } }; rootPan.Children.AddRange(new List <IControl> { blurb1, openF.holder, resultGd }); }
private void ExecuteShowBusyIndicator(object x) { IsBusy = !IsBusy; if (IsBusy) { DispatcherTimer.RunOnce(() => { IsBusy = false; }, TimeSpan.FromSeconds(30)); } }
private void InitializeComponent() { AvaloniaXamlLoader.Load(this); DispatcherTimer.RunOnce(() => { GridView gridView = this.FindControl <GridView>("GridView"); if (gridView != null && gridView.SelectedItem != null) { gridView.ScrollIntoView(gridView.SelectedItem); } }, TimeSpan.FromMilliseconds(1)); }
public override void OnInitialized(IContainerProvider containerProvider) { base.OnInitialized(containerProvider); containerProvider.Resolve <IEventAggregator>().GetEvent <AllModulesLoaded>() .Subscribe(() => { DispatcherTimer.RunOnce(() => { containerProvider.Resolve <IAnniversarySummaryService>().TryOpenDefaultSummary(); }, TimeSpan.FromMilliseconds(1)); }, true); }
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { base.OnAttachedToVisualTree(e); TablesListBox = this.FindControl <ListBox>("TablesListBox"); SelectionAdapter = new SelectingItemsControlSelectionAdapter(TablesListBox); DispatcherTimer.RunOnce(() => { var searchTextBox = this.FindControl <TextBox>("SearchTextBox"); searchTextBox?.Focus(); searchTextBox?.SelectAll(); }, TimeSpan.FromMilliseconds(1)); }
public OptionsTabView() { InitializeComponent(); var flip = this.FindControl <Button>("Flip"); flip.Command = ReactiveCommand.Create(() => { var window = (Window)VisualRoot; window.Classes.Add("DoAFlip"); DispatcherTimer.RunOnce(() => { window.Classes.Remove("DoAFlip"); }, TimeSpan.FromSeconds(1)); }); }
void DisposeRenderTarget() { using (var l = _lock.TryLock()) { if (l == null) { // We are still trying to render on the render thread, try again a bit later DispatcherTimer.RunOnce(DisposeRenderTarget, TimeSpan.FromMilliseconds(50), DispatcherPriority.Background); return; } Layers.Clear(); RenderTarget?.Dispose(); RenderTarget = null; } }
public void Spawn(Visual parent, Rect position, BaseDatabaseCellViewModel cellModel) { this.cellModel = cellModel; var flagsComboBox = new CompletionComboBox(); flagsComboBox.Items = cellModel.Items; flagsComboBox.SelectedItem = cellModel.OptionValue; flagsComboBox.HideButton = true; flagsComboBox.IsLightDismissEnabled = false; // we are handling it ourselves, without doing .Handled = true so that as soon as user press outside of popup, the click is treated as actual click flagsComboBox.Closed += CompletionComboBoxOnClosed; if (!AttachAsAdorner(parent, position, flagsComboBox)) { return; } DispatcherTimer.RunOnce(() => { flagsComboBox.IsDropDownOpen = true; }, TimeSpan.FromMilliseconds(1)); }
public void Spawn(Visual parent, Rect position, IParameterValue <long> parameter) { this.parameter = parameter; var flagsComboBox = new FlagComboBox(); flagsComboBox.Flags = parameter.Parameter.Items; flagsComboBox.SelectedValue = parameter.Value; flagsComboBox.HideButton = true; flagsComboBox.IsLightDismissEnabled = false; // we are handling it ourselves, without doing .Handled = true so that as soon as user press outside of popup, the click is treated as actual click flagsComboBox.Closed += CompletionComboBoxOnClosed; if (!AttachAsAdorner(parent, position, flagsComboBox)) { return; } DispatcherTimer.RunOnce(() => { flagsComboBox.IsDropDownOpen = true; }, TimeSpan.FromMilliseconds(1)); }
public void Spawn(Visual parent, Rect position, string text, bool selectAll, Action <string> onApply) { currentOnApply = onApply; var textBox = new TextBox() { }; textBox.MinWidth = 0; textBox.MinHeight = 0; textBox.Padding = new Thickness(5, 0, 0, 0); textBox.Text = text; textBox.KeyBindings.Add(new KeyBinding() { Gesture = new KeyGesture(Key.Enter), Command = new DelegateCommand(() => Despawn(true)) }); textBox.KeyBindings.Add(new KeyBinding() { Gesture = new KeyGesture(Key.Escape), Command = new DelegateCommand(() => Despawn(false)) }); textBox.LostFocus += ElementLostFocus; if (!AttachAsAdorner(parent, position, textBox)) { return; } DispatcherTimer.RunOnce(textBox.Focus, TimeSpan.FromMilliseconds(1)); if (selectAll) { textBox.SelectAll(); } else { textBox.SelectionStart = textBox.SelectionEnd = textBox.Text.Length; } }
/// <summary> /// Called when a new item container is materialized, to set its selected state. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> private void ContainerMaterialized(object sender, ItemContainerEventArgs e) { var selectedItem = SelectedItem; if (selectedItem != null) { foreach (var container in e.Containers) { if (container.Item == selectedItem) { ((TreeViewItem)container.ContainerControl).IsSelected = true; if (AutoScrollToSelectedItem) { DispatcherTimer.RunOnce( container.ContainerControl.BringIntoView, TimeSpan.Zero); } break; } } } }
private void ClipboardOnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(Clipboard.CurrentIndex)) { if (Clipboard.CurrentIndex < 0 || Clipboard.SuppressRestore) { return; } AddLogVerbose($"Clipboard change: {Clipboard.CurrentIndex}"); if (Clipboard.ReallocatedLayerCount) { DispatcherTimer.RunOnce(() => { RefreshProperties(); ResetDataContext(); }, TimeSpan.FromMilliseconds(1)); } ShowLayer(); return; } }
public static void Invoke(Action action, DispatcherPriority dispatcherPriority = DispatcherPriority.Background) { DispatcherTimer.RunOnce(() => { action(); }, new TimeSpan(0), dispatcherPriority); }
public AppUI() { var lb1 = new ListBox(); lb1.Width = lb1.Height = 300; rootPan.Spacing = 6; var blurb1 = App.TextBlock; blurb1.TextAlignment = TextAlignment.Center; blurb1.Text = "Connect to an FTP server."; var partcPanel = App.HorizontalStackPanel; partcPanel.HorizontalAlignment = HorizontalAlignment.Center; var hostBlurb = App.TextBlock; hostBlurb.Text = "Host:"; var hostField = App.TextBox; hostField.Width = 130; var portBlurb = App.TextBlock; portBlurb.Text = "Port:"; var portField = App.TextBox; portField.Width = 50; portField.Text = "21"; var userBlurb = App.TextBlock; userBlurb.Text = "Username:"******"Password:"******"Connect"; var disconnectBt = App.Button; disconnectBt.Content = "Disconnect"; disconnectBt.IsEnabled = false; partcPanel.Children.AddRange(new List <IControl> { hostBlurb, hostField, portBlurb, portField, userBlurb, userField, passBlurb, passField, connectBt, disconnectBt }); var upDirLocal = App.Button; upDirLocal.Content = "Up"; upDirLocal.Width = 50; var ph1 = App.TextBlock; var ph2 = App.TextBlock; var ph3 = App.TextBlock; ph1.Text = ph2.Text = ph3.Text = " "; ph1.Width = ph2.Width = 240; var ulBt = App.Button; ulBt.Content = "Upload >"; var upDirRemote = App.Button; upDirRemote.Content = "Up"; upDirRemote.Width = 50; var dlBt = App.Button; dlBt.Content = "< Download"; upDirLocal.IsEnabled = false; ulBt.IsEnabled = false; upDirRemote.IsEnabled = false; dlBt.IsEnabled = false; var partcPanel2 = App.HorizontalStackPanel; partcPanel2.HorizontalAlignment = HorizontalAlignment.Center; partcPanel2.Children.AddRange(new List <IControl> { upDirLocal, ph1, ulBt, dlBt, ph2, upDirRemote }); var border1 = new Border() { BorderThickness = new Thickness(1), BorderBrush = Brushes.LightSlateGray, Width = 900 }; border1.Child = partcPanel2; var localLb = App.DataGrid; var remoteLb = App.DataGrid; localLb.Width = remoteLb.Width = 430; localLb.Height = remoteLb.Height = 350; localLb.CanUserReorderColumns = remoteLb.CanUserReorderColumns = true; localLb.CanUserResizeColumns = remoteLb.CanUserResizeColumns = true; void ShowErrorMessage(string message) { string oriBlurb = blurb1.Text; blurb1.Text = message; DispatcherTimer.RunOnce(() => { blurb1.Text = oriBlurb; }, new TimeSpan(0, 0, 0, 5, 0)); } upDirRemote.Click += async(z, zz) => { List <string> curDirSegs = (await client.GetWorkingDirectoryAsync()).Split('/').ToList(); if (curDirSegs.Count() >= 0) { if (curDirSegs.Count() > 0) { await client.SetWorkingDirectoryAsync("/" + string.Join("/", curDirSegs.Take(curDirSegs.Count - 1))); } else { await client.SetWorkingDirectoryAsync("/"); } remoteLb.Items = (await lib.ListDirAsync(client)).Select(zzz => new { zzz.Type, zzz.Name, zzz.Size, zzz.Created, zzz.Modified, zzz.FullName }); } }; upDirLocal.Click += (z, zz) => { var curDirSegs = new Uri(currentLocalDir); if (curDirSegs.Segments.Count() > 1) { string newLocDir = Directory.GetParent(curDirSegs.LocalPath).FullName; string[] newDirFilesnames = Directory.GetFileSystemEntries(newLocDir); localLb.Items = newDirFilesnames.Select(zzz => new FileInfo(zzz)).Select(zzz => new { zzz.Attributes, zzz.Name, Size = !zzz.Attributes.HasFlag(FileAttributes.Directory) ? zzz.Length : 0, zzz.CreationTime, zzz.LastWriteTime, zzz.FullName }); currentLocalDir = newLocDir; } }; remoteLb.CellPointerPressed += async(z, zz) => { var selectedItem = remoteLb.Items.Cast <dynamic>().ElementAt(zz.Row.GetIndex()); if (selectedItem.Type.Equals(FtpFileSystemObjectType.Directory)) { await client.SetWorkingDirectoryAsync(selectedItem.FullName); remoteLb.Items = (await lib.ListDirAsync(client)).Select(zzz => new { zzz.Type, zzz.Name, zzz.Size, zzz.Created, zzz.Modified, zzz.FullName }); } }; localLb.CellPointerPressed += async(z, zz) => { var selectedItem = localLb.Items.Cast <dynamic>().ElementAt(zz.Row.GetIndex()); if (selectedItem.Attributes.HasFlag(FileAttributes.Directory)) { string[] newDirFilesnames = Directory.GetFileSystemEntries(selectedItem.FullName); await client.GetWorkingDirectoryAsync(); localLb.Items = newDirFilesnames.Select(zzz => new FileInfo(zzz)).Select(zzz => new { zzz.Attributes, zzz.Name, Size = !zzz.Attributes.HasFlag(FileAttributes.Directory) ? zzz.Length : 0, zzz.CreationTime, zzz.LastWriteTime, zzz.FullName }); currentLocalDir = selectedItem.FullName; } }; ph3.Width = 20; var partcPanel3 = App.HorizontalStackPanel; partcPanel3.HorizontalAlignment = HorizontalAlignment.Center; partcPanel3.Children.AddRange(new List <IControl> { localLb, ph3, remoteLb }); var border2 = new Border() { BorderThickness = new Thickness(1), BorderBrush = Brushes.LightSlateGray, Width = 900 }; border2.Child = partcPanel3; rootPan.Children.AddRange(new List <IControl> { blurb1, partcPanel, border1, border2 }); dlBt.Click += async(z, zz) => { try { foreach (var item in remoteLb.SelectedItems) { ((App)Application.Current).LoadingBar.IsIndeterminate = true; await lib.DownloadFileAsync(client, new Uri(currentLocalDir), ((dynamic)item).Name); ((App)Application.Current).LoadingBar.IsIndeterminate = false; localLb.Items = Directory.GetFileSystemEntries(Directory.GetCurrentDirectory()).Select(zzz => new FileInfo(zzz)).Select(zzz => new { zzz.Attributes, zzz.Name, Size = !zzz.Attributes.HasFlag(FileAttributes.Directory) ? zzz.Length : 0, zzz.CreationTime, zzz.LastWriteTime, zzz.FullName }).ToList(); } } catch (Exception e) { ((App)Application.Current).LoadingBar.IsIndeterminate = false; ShowErrorMessage(e.Message); } }; ulBt.Click += async(z, zz) => { try { foreach (var item in localLb.SelectedItems) { ((App)Application.Current).LoadingBar.IsIndeterminate = true; await lib.UploadFileAsync(client, new Uri(((dynamic)item).FullName)); ((App)Application.Current).LoadingBar.IsIndeterminate = false; remoteLb.Items = (await lib.ListDirAsync(client)).Select(zzz => new { zzz.Type, zzz.Name, zzz.Size, zzz.Created, zzz.Modified, zzz.FullName }); } } catch (Exception e) { ((App)Application.Current).LoadingBar.IsIndeterminate = false; ShowErrorMessage(e.Message); } }; connectBt.Click += async(z, zz) => { try { if (string.IsNullOrWhiteSpace(hostField.Text)) { throw new ArgumentNullException(); } ((App)Application.Current).LoadingBar.IsIndeterminate = true; client = await lib.ConnectToFtpAsync(hostField.Text, int.Parse(portField.Text), userField.Text, passField[TextBox.TextProperty].ToString()); remoteLb.Items = (await lib.ListDirAsync(client)).Select(zzz => new { zzz.Type, zzz.Name, zzz.Size, zzz.Created, zzz.Modified, zzz.FullName }); localLb.Items = Directory.GetFileSystemEntries(Directory.GetCurrentDirectory()).Select(zzz => new FileInfo(zzz)).Select(zzz => new { zzz.Attributes, zzz.Name, Size = !zzz.Attributes.HasFlag(FileAttributes.Directory) ? zzz.Length : 0, zzz.CreationTime, zzz.LastWriteTime, zzz.FullName }).ToList(); currentLocalDir = Directory.GetCurrentDirectory(); connectBt.IsEnabled = false; disconnectBt.IsEnabled = true; hostField.IsEnabled = false; portField.IsEnabled = false; userField.IsEnabled = false; passField.IsEnabled = false; upDirLocal.IsEnabled = true; ulBt.IsEnabled = true; upDirRemote.IsEnabled = true; dlBt.IsEnabled = true; ((App)Application.Current).LoadingBar.IsIndeterminate = false; } catch (Exception e) { ((App)Application.Current).LoadingBar.IsIndeterminate = false; if (e is ArgumentNullException || e is ArgumentException || e is FormatException) { ShowErrorMessage("Empty or invalid connection parameter(s)."); } else { ShowErrorMessage(e.Message); } } }; disconnectBt.Click += (z, zz) => { client.Disconnect(); client.Dispose(); connectBt.IsEnabled = true; disconnectBt.IsEnabled = false; hostField.IsEnabled = true; portField.IsEnabled = true; userField.IsEnabled = true; passField.IsEnabled = true; upDirLocal.IsEnabled = false; ulBt.IsEnabled = false; upDirRemote.IsEnabled = false; dlBt.IsEnabled = false; localLb.Items = null; remoteLb.Items = null; }; }
public void Delay(Action action, TimeSpan delay) { DispatcherTimer.RunOnce(action, delay); }