コード例 #1
0
        /// <summary>
        /// The button delete on click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ButtonDeleteOnClick(object sender, RoutedEventArgs e)
        {
            var selectedRow = ExtendedVisualTreeHelper.GetVisualParent <DataGridRow>(sender as DependencyObject).Item;

            if (this.routes.Contains((Route)selectedRow))
            {
                this.routes.Remove((Route)selectedRow);
            }

            if (this.routes.Count == 0)
            {
                this.TextBlockForBlankRow.Visibility = Visibility.Visible;
                this.DataGrid.Visibility             = Visibility.Collapsed;
            }

            this.DataGrid.ItemsSource = this.routes;
        }
コード例 #2
0
        /// <summary>
        /// The button edit on click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private async void ButtonEditOnClick(object sender, RoutedEventArgs e)
        {
            var selectedRow = ExtendedVisualTreeHelper.GetVisualParent <DataGridRow>(sender as DependencyObject).Item;

            var dialog2 = new AddRouteDialog {
                DataContext = new AddRouteDialogViewModel((Route)selectedRow)
            };

            var result2 = await DialogHost.Show(dialog2, "RootDialog")
                          .ConfigureAwait(false);

            if (result2 != null)
            {
                this.Dispatcher.Invoke(
                    () =>
                {
                    this.routes.Remove((Route)selectedRow);
                    this.routes.Add((Route)result2);
                    this.routes = new ObservableCollection <Route>(this.routes.DistinctBy(r => r.StationCode));
                    this.DataGrid.ItemsSource = this.routes;
                },
                    DispatcherPriority.Normal);
            }
        }