private void Window_Loaded(object?sender, RoutedEventArgs e) { CommandLine parser = new(false); parser.AddHeader(CommandLine.ExecutableFileName + " [/BringToFront]"); bool bringToFront = false; parser.AddSwitch("BringToFront", "Makes the app attempt to force its way to the foreground when launched.", value => bringToFront = value); switch (parser.Parse()) { case CommandLineParseResult.Valid: if (bringToFront) { this.ExecuteWhenIdle(() => WindowsUtility.BringToFront(this)); } break; case CommandLineParseResult.HelpRequested: this.ExecuteWhenIdle(() => WindowsUtility.ShowInfo(this, parser.CreateMessage())); break; default: this.ExecuteWhenIdle(() => WindowsUtility.ShowError(this, parser.CreateMessage())); break; } }
private void GridPreviewCanExecute(object sender, CanExecuteRoutedEventArgs e) { // Idea came from https://stackoverflow.com/a/33187654/1882616. if (e.Command == DataGrid.DeleteCommand) { // The new/insert row is an internal "NamedObject" object not a GridRow. if (this.grid.SelectedItem is GridRow row) { string[] usingLocations = this.profile.Locations.Where(l => l.PeerGroup.Id == row.Id).Select(l => l.Name).ToArray(); if (usingLocations.Length > 0) { string suffix = usingLocations.Length == 1 ? string.Empty : "s"; string locations = string.Join("\n", usingLocations); WindowsUtility.ShowInfo( this, $"Peer group \"{row.Name}\" can't be deleted because it is still in use by the following location{suffix}:\n\n{locations}"); e.Handled = true; } } } }