private void OnActualWidthPropertyChanged(object sender, EventArgs e) { try { ColumnActualWidthProperty?.Invoke(this, new DataGridColumnEventArgs((DataGridColumn)sender)); } catch (Exception ex) { MessageBox.Show(ExceptionFormater.AppendMethod(ex, MethodBase.GetCurrentMethod())); } }
private void _window_Closed(object sender, EventArgs e) { try { this.Dispose(); } catch (Exception ex) { MessageBox.Show(ExceptionFormater.AppendMethod(ex, MethodBase.GetCurrentMethod())); } }
/// <summary> /// Kopiuje zaznaczoną zawartość do schowka. /// </summary> public void CopySelectedContentToClipboard() { try { ExecutedRoutedEventArgs args = (ExecutedRoutedEventArgs)CONSTRUCTORINFO_EXECUTEDROUTEDEVENTARGS.Invoke(new object[] { ApplicationCommands.Copy, null }); args.RoutedEvent = DataObject.CopyingEvent; args.Source = this; OnExecutedCopyInternal(args); } catch (Exception ex) { MessageBox.Show(ExceptionFormater.AppendMethod(ex, MethodBase.GetCurrentMethod())); } }
private void DataGrid_Loaded(object sender, RoutedEventArgs e) { try { if (this.Parent != null) { if (_window == null) { _window = Window.GetWindow(this); if (_window != null && !this.DesignMode) { _window.Closed += _window_Closed; } } } } catch (Exception ex) { MessageBox.Show(ExceptionFormater.AppendMethod(ex, MethodBase.GetCurrentMethod())); } }
private void Columns_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { try { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (var column in e.NewItems) { _propertyDescriptorActualWidth.AddValueChanged(column, OnActualWidthPropertyChanged); } } else if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (var column in e.OldItems) { _propertyDescriptorActualWidth.RemoveValueChanged(column, OnActualWidthPropertyChanged); } } } catch (Exception ex) { MessageBox.Show(ExceptionFormater.AppendMethod(ex, MethodBase.GetCurrentMethod())); } }
/// <summary> /// Usuwa element. /// </summary> /// <param name="control">Element do usunięcia.</param> /// <param name="refreshParent">Określa czy odświeżyć rodzica kontrolki.</param> /// <returns>True, jeśli element został usunięty, w przeciwnym razie false.</returns> public static bool Remove(this FrameworkElement control, bool refreshParent) { bool removed = false; if (control.Parent == null) { return(removed); } Type parentType = control.Parent.GetType(); dynamic parent = control.Parent; if (parentType.GetProperty("Children") != null) { parent.Children.Remove(control); removed = true; } else if (parentType.GetProperty("Child") != null) { parent.Child = null; removed = true; } else if (parentType.GetProperty("Content") != null) { parent.Content = null; removed = true; } else if (parentType.GetProperty("Items") != null) { if (parent.Items.Contains(control)) { parent.Items.Remove(control); removed = true; } } else if (parentType.FullName == "System.Windows.Controls.ToolBarTray") { var c = parent as FrameworkElement; if (c != null) { return(c.Remove(refreshParent)); } } if (removed) { if (refreshParent) { if (removed && parentType.GetMethod("InvalidateMeasure") != null && parent != null) { // Odświeżamy rodzica. parent.InvalidateMeasure(); } } } else { if (DebugEx.IsDebug) { MessageBox.Show(ExceptionFormater.AppendMethod(new Exception("Nie znaleziono elementu."), MethodBase.GetCurrentMethod()), System.Windows.Forms.Application.CompanyName); } } return(removed); }
/// <summary> /// Metoda sprzątająca. Zwalnia zasoby zarządzane. /// </summary> private void Cleaner() { try { //BindingOperations.ClearAllBindings(this); if (_window != null) { _window.Closed -= _window_Closed; } _window = null; Loaded -= DataGrid_Loaded; Columns.CollectionChanged -= Columns_CollectionChanged; if (_scrollViewer != null) { _scrollViewer = null; } foreach (DataGridColumn column in Columns) { _propertyDescriptorActualWidth.RemoveValueChanged(column, OnActualWidthPropertyChanged); } //if (this.Items != null) //{ // BindingExpressionBase beb = BindingOperations.GetBindingExpressionBase(this, ItemsSourceProperty); // if (beb == null) // { // // ItemsSource nie jest powiązany z danymi. // UserControlBase.ItemsDispose(this.Items); // bool isUsingItemsSource = PropertyInfoEx.GetValue<bool>(this.Items, "IsUsingItemsSource"); // if (!isUsingItemsSource) // { // // 'this.ItemsSource' trzeba wyczyścić przed 'this.Items.Clear()', ponieważ zgłoszony zostanie wyjątek. // this.ItemsSource = null; // this.Items.Clear(); // } // } // this.ItemsSource = null; // this.Items.DetachFromSourceCollection(); //} //this.ItemsSource = null; this.ColumnHeaderStyle = null; this.RowHeaderStyle = null; this.RowStyle = null; this.CellStyle = null; this.Template = null; this.Style = null; if (!string.IsNullOrEmpty(this.Name) && this.FindName(this.Name) != null) { this.UnregisterName(this.Name); } //this.Remove(false); } catch (Exception ex) { MessageBox.Show(ExceptionFormater.AppendMethod(ex, MethodBase.GetCurrentMethod())); } }