private void Element_SizeChanged(object sender, SizeChangedEventArgs e) { //Find DataGridDetailsPresenter DataGridDetailsPresenter rowDetailPresenter = null; var element = this.AssociatedObject; while (element != null) { rowDetailPresenter = element as DataGridDetailsPresenter; if (rowDetailPresenter != null) { break; } element = (FrameworkElement)VisualTreeHelper.GetParent(element); } if (rowDetailPresenter != null) { var row = UIHelper.GetParentOf <DataGridRow>(this.AssociatedObject); if (row != null && row.DetailsVisibility == Visibility.Visible) { //Set height rowDetailPresenter.ContentHeight = this.AssociatedObject.ActualHeight; } } }
private void DeleteFitment_Button_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Do you want to delete selected fitments?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { using (var db = new ProductDBEntitie()) { DataGridRow row = (DataGridRow)(DataTable.ItemContainerGenerator.ContainerFromItem(DataTable.SelectedItem)); DataGridDetailsPresenter presenter = FindVisualChild <DataGridDetailsPresenter>(row); DataTemplate template = presenter.ContentTemplate; DataGrid dg = (DataGrid)template.FindName("datagridf", presenter); DataGridCheckBoxColumn cb = (DataGridCheckBoxColumn)template.FindName("NOf", presenter); List <int> deleteFitment = new List <int>(); foreach (Fitment f in dg.ItemsSource) { try { if (((CheckBox)cb.GetCellContent(f)).IsChecked == true) { deleteFitment.Add(f.id); Fitment fitment = (from c in db.Fitment where c.id == f.id select c).FirstOrDefault(); if (fitment != null) { db.Fitment.Remove(fitment); db.SaveChanges(); } } } catch { } } new ReadFitmentsDB(dg, statusBar); } } }
private void edit_Click(object sender, RoutedEventArgs e) { DataGridRow dgRow = (DataGridRow)(gridClubMember.ItemContainerGenerator.ContainerFromItem(gridClubMember.SelectedItem)); ClubMember selectedClub = gridClubMember.Items[gridClubMember.SelectedIndex] as ClubMember; if (dgRow == null) { return; } DataGridDetailsPresenter dgdPresenter = FindVisualChild <DataGridDetailsPresenter>(dgRow); DataTemplate template = dgdPresenter.ContentTemplate; TextBox textBoxFName = (TextBox)template.FindName("editFirstName", dgdPresenter); TextBox textBoxLName = (TextBox)template.FindName("editLastName", dgdPresenter); if (whoUse.Hierarchy == Hierarchy.Clubmember || whoUse.Hierarchy == Hierarchy.Customer || whoUse.Hierarchy == Hierarchy.Worker) { textBoxFName.IsReadOnly = true; textBoxLName.IsReadOnly = true; MessageBox.Show("You are not allowed to edit this field"); } else { if (textBoxFName == null || textBoxLName == null) { MessageBox.Show("you have to write somthing"); } else { if (textBoxFName.Text.Length < 1) { throw new Exception("Invalid First Name, Must Have Atleast One Character"); } selectedClub.FirstName = textBoxFName.Text; if (textBoxLName.Text.Length < 1) { throw new Exception("Invalid Last Name, Must Have Atleast One Character"); } selectedClub.LastName = textBoxLName.Text; try { itsBL.edit(selectedClub); itsBL.saveDataToFile(); MessageBox.Show("Changes have been done"); dgRow.DetailsVisibility = Visibility.Collapsed; gridClubMember.Items.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void edit_Click(object sender, RoutedEventArgs e) { DataGridRow dgRow = (DataGridRow)(gridDepartment.ItemContainerGenerator.ContainerFromItem(gridDepartment.SelectedItem)); Department selectedDep = gridDepartment.Items[gridDepartment.SelectedIndex] as Department; if (dgRow == null) { return; } DataGridDetailsPresenter dgdPresenter = FindVisualChild <DataGridDetailsPresenter>(dgRow); DataTemplate template = dgdPresenter.ContentTemplate; TextBox textBoxName = (TextBox)template.FindName("editName", dgdPresenter); if (whoUse.Hierarchy == Hierarchy.Clubmember || whoUse.Hierarchy == Hierarchy.Customer || whoUse.Hierarchy == Hierarchy.Worker) { textBoxName.IsReadOnly = true; MessageBox.Show("You are not allowed to edit this field"); } else { if (textBoxName == null) { MessageBox.Show("you have to write somthing"); } else { if (textBoxName.Text.Length < 1) { throw new Exception("Invalid First Name, Must Have Atleast One Character"); } selectedDep.Name = textBoxName.Text; try { itsBL.edit(selectedDep); itsBL.saveDataToFile(); MessageBox.Show("Changes have been done"); tablePanel.Children.Clear(); DepartmentT showProduct = new DepartmentT(itsBL, Permanent, whoUse); tablePanel.Children.Add(showProduct); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
FindDataGridDetailsPresenter(DependencyObject child) { DependencyObject parent = VisualTreeHelper.GetParent(child); // Check if this is the end of the tree if (parent == null) { return(null); } DataGridDetailsPresenter parentWindow = parent as DataGridDetailsPresenter; if (parentWindow != null) { return(parentWindow); } else { // Use recursion until it reaches a Window return(FindDataGridDetailsPresenter(parent)); } }
private void openReceipt_Click(object sender, RoutedEventArgs e) { DataGridRow dgRow = (DataGridRow)(gridTransection.ItemContainerGenerator.ContainerFromItem(gridTransection.SelectedItem)); selectedTra = gridTransection.Items[gridTransection.SelectedIndex] as Transaction; try { if (dgRow == null) { return; } DataGridDetailsPresenter dgdPresenter = FindVisualChild <DataGridDetailsPresenter>(dgRow); Receipt toShow = selectedTra.Receipt; DataTemplate template = dgdPresenter.ContentTemplate; TextBox textBoxReci = (TextBox)template.FindName("reciept", dgdPresenter); string rec = Convert.ToString(toShow.toString()); textBoxReci.Text = rec; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected override void Invoke(object parameter) { //Find DataGridDetailsPresenter DataGridDetailsPresenter rowDetailPresenter = null; var element = this.AssociatedObject; while (element != null) { rowDetailPresenter = element as DataGridDetailsPresenter; if (rowDetailPresenter != null) { break; } element = (FrameworkElement)VisualTreeHelper.GetParent(element); } //Refresh height because DataGrid row height only grows but won't shrink back if (rowDetailPresenter != null) { rowDetailPresenter.ContentHeight = 0; rowDetailPresenter.UpdateLayout(); } }
public static IObservable <EventPattern <MouseButtonEventArgs> > MouseLeftButtonDownObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <MouseButtonEventHandler, MouseButtonEventArgs>(h => This.MouseLeftButtonDown += h, h => This.MouseLeftButtonDown -= h)); }
public static IObservable <EventPattern <MouseButtonEventArgs> > PreviewMouseUpObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <MouseButtonEventHandler, MouseButtonEventArgs>(h => This.PreviewMouseUp += h, h => This.PreviewMouseUp -= h)); }
public static IObservable <EventPattern <ContextMenuEventArgs> > ContextMenuClosingObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <ContextMenuEventHandler, ContextMenuEventArgs>(h => This.ContextMenuClosing += h, h => This.ContextMenuClosing -= h)); }
public static IObservable <EventPattern <ToolTipEventArgs> > ToolTipClosingObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <ToolTipEventHandler, ToolTipEventArgs>(h => This.ToolTipClosing += h, h => This.ToolTipClosing -= h)); }
public static IObservable <EventPattern <ManipulationCompletedEventArgs> > ManipulationCompletedObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <EventHandler <ManipulationCompletedEventArgs>, ManipulationCompletedEventArgs>(h => This.ManipulationCompleted += h, h => This.ManipulationCompleted -= h)); }
public static IObservable <EventPattern <DragEventArgs> > PreviewDragLeaveObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <DragEventHandler, DragEventArgs>(h => This.PreviewDragLeave += h, h => This.PreviewDragLeave -= h)); }
private void edit_Click(object sender, RoutedEventArgs e) { DataGridRow dgRow = (DataGridRow)(gridEmployee.ItemContainerGenerator.ContainerFromItem(gridEmployee.SelectedItem)); Employee selectedEmpo = gridEmployee.Items[gridEmployee.SelectedIndex] as Employee; if (dgRow == null) { return; } DataGridDetailsPresenter dgdPresenter = FindVisualChild <DataGridDetailsPresenter>(dgRow); DataTemplate template = dgdPresenter.ContentTemplate; TextBox textBoxFName = (TextBox)template.FindName("editFirstName", dgdPresenter); TextBox textBoxLName = (TextBox)template.FindName("editLastName", dgdPresenter); TextBox textBoxDepID = (TextBox)template.FindName("editDepID", dgdPresenter); TextBox textBoxSalary = (TextBox)template.FindName("editSalary", dgdPresenter); TextBox textBoxSuper = (TextBox)template.FindName("editSuper", dgdPresenter); if (whoUse.Hierarchy == Hierarchy.Clubmember || whoUse.Hierarchy == Hierarchy.Customer || whoUse.Hierarchy == Hierarchy.Worker) { textBoxFName.IsReadOnly = true; textBoxLName.IsReadOnly = true; textBoxDepID.IsReadOnly = true; textBoxSalary.IsReadOnly = true; textBoxSuper.IsReadOnly = true; MessageBox.Show("You are not allowed to edit this field"); } else { if (textBoxFName == null || textBoxLName == null || textBoxDepID == null || textBoxSalary == null || textBoxSuper == null) { MessageBox.Show("you have to fill all the empty fields"); } else { try { if (textBoxFName.Text.Length < 1) { throw new Exception("Invalid First Name, Must Have Atleast One Character"); } selectedEmpo.FirstName = textBoxFName.Text; if (textBoxFName.Text.Length < 1) { throw new Exception("Invalid Last Name, Must Have Atleast One Character"); } selectedEmpo.LastName = textBoxLName.Text; InputCheck.isInt(textBoxDepID.Text, " department ID "); selectedEmpo.DepartmentID = Convert.ToInt32(textBoxDepID.Text); InputCheck.isDouble(textBoxSalary.Text, " salary "); selectedEmpo.Salary = Convert.ToDouble(textBoxSalary.Text); InputCheck.isInt(textBoxSuper.Text, " supervisor ID "); selectedEmpo.SupervisorID = Convert.ToInt32(textBoxSuper.Text); itsBL.edit(selectedEmpo); itsBL.saveDataToFile(); MessageBox.Show("Changes have been done"); tablePanel.Children.Clear(); DepartmentT showProduct = new DepartmentT(itsBL, Permanent, whoUse); tablePanel.Children.Add(showProduct); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
public static IObservable <EventPattern <RoutedEventArgs> > LostFocusObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(h => This.LostFocus += h, h => This.LostFocus -= h)); }
public static IObservable <EventPattern <RoutedEventArgs> > UnloadedObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(h => This.Unloaded += h, h => This.Unloaded -= h)); }
public static IObservable <EventPattern <EventArgs> > LayoutUpdatedObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <EventHandler, EventArgs>(h => This.LayoutUpdated += h, h => This.LayoutUpdated -= h)); }
public static IObservable <EventPattern <TouchEventArgs> > TouchLeaveObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <EventHandler <TouchEventArgs>, TouchEventArgs>(h => This.TouchLeave += h, h => This.TouchLeave -= h)); }
public static IObservable <EventPattern <TouchEventArgs> > PreviewTouchUpObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <EventHandler <TouchEventArgs>, TouchEventArgs>(h => This.PreviewTouchUp += h, h => This.PreviewTouchUp -= h)); }
public static IObservable <EventPattern <DragEventArgs> > DropObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <DragEventHandler, DragEventArgs>(h => This.Drop += h, h => This.Drop -= h)); }
public static IObservable <EventPattern <QueryContinueDragEventArgs> > QueryContinueDragObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <QueryContinueDragEventHandler, QueryContinueDragEventArgs>(h => This.QueryContinueDrag += h, h => This.QueryContinueDrag -= h)); }
public static IObservable <EventPattern <TextCompositionEventArgs> > TextInputObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <TextCompositionEventHandler, TextCompositionEventArgs>(h => This.TextInput += h, h => This.TextInput -= h)); }
private void dataGrid_CellValueChanged(object sender, Control.DataGridCellEditEndingEventArgs e) { if (e.EditAction == Control.DataGridEditAction.Commit) { WPFdataGrid.DataGridControl wPFdataGrid = elementHost1.Child as WPFdataGrid.DataGridControl; var dataGridView = wPFdataGrid.grid; Control.DataGridRow dataRow = e.Row as Control.DataGridRow; PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(dataRow.Item); DataGridDetailsPresenter presenter = FindVisualChild <DataGridDetailsPresenter>(dataRow); DataTemplate detail = presenter.ContentTemplate; Int16.TryParse(properties["HP"].GetValue(dataRow.Item).ToString(), out Int16 HP); Int16.TryParse(properties["Attack"].GetValue(dataRow.Item).ToString(), out Int16 Attack); Int16.TryParse(properties["Defense"].GetValue(dataRow.Item).ToString(), out Int16 Defense); Int16.TryParse(properties["SPAttack"].GetValue(dataRow.Item).ToString(), out Int16 SPAttack); Int16.TryParse(properties["SPDefense"].GetValue(dataRow.Item).ToString(), out Int16 SPDefense); Int16.TryParse(properties["Speed"].GetValue(dataRow.Item).ToString(), out Int16 Speed); Int16 CapRate = 0; Int16 ExpDrop = 0; try { Control.DataGrid detailGrid = detail.FindName("details", presenter) as Control.DataGrid; PropertyDescriptorCollection detailProperties = TypeDescriptor.GetProperties(detailGrid.Items.CurrentItem); Int16.TryParse(detailProperties["CapRate"]?.GetValue(detailGrid.Items?.CurrentItem)?.ToString(), out CapRate); Int16.TryParse(detailProperties["ExpDrop"]?.GetValue(detailGrid.Items?.CurrentItem)?.ToString(), out ExpDrop); } catch { using (Pokemon db = new Pokemon()) { try { CapRate = db.PokemonBaseStats.Where(p => p.PName == properties["PName"].GetValue(dataRow.Item).ToString()).Single().PokemonCapRate.CapRate; ExpDrop = db.PokemonBaseStats.Where(p => p.PName == properties["PName"].GetValue(dataRow.Item).ToString()).Single().PokemonCapRate.ExpDrop; } catch { CapRate = 0; ExpDrop = 0; } } } pokemon = new PokemonBaseStat() { PName = properties["PName"].GetValue(dataRow.Item)?.ToString(), HP = HP, Attack = Attack, Defense = Defense, SPAttack = SPAttack, SPDefense = SPDefense, Speed = Speed, Type1 = properties["Type1"].GetValue(dataRow.Item)?.ToString(), Type2 = properties["Type2"].GetValue(dataRow.Item)?.ToString(), PokemonCapRate = new PokemonCapRate() { PName = properties["PName"].GetValue(dataRow.Item)?.ToString(), CapRate = CapRate, ExpDrop = ExpDrop } }; ValidationContext validate = new ValidationContext(pokemon, null, null); IList <ValidationResult> errors = new List <ValidationResult>(); if (!Validator.TryValidateObject(pokemon, validate, errors, true)) { e.Cancel = true; EventArgs.Cancel = true; EventArgs.Error = null; Control.DataErrorValidationRule validationRule = new Control.DataErrorValidationRule(); Control.ValidationError error = new Control.ValidationError(validationRule, dataRow.BindingGroup.BindingExpressions); EventArgs.Error = $"{errors.First().ErrorMessage}"; error.ErrorContent = $"{errors.First().ErrorMessage}"; foreach (ValidationResult result in errors.Skip(1)) { EventArgs.Error += $"\n{result.ErrorMessage}"; error.ErrorContent += $"\n{result.ErrorMessage}"; } foreach (var binding in dataRow.BindingGroup.BindingExpressions) { Control.Validation.MarkInvalid(dataRow.BindingGroup.BindingExpressions.First(), error); } } else { Control.DataErrorValidationRule validationRule = new Control.DataErrorValidationRule(); Control.ValidationError error = new Control.ValidationError(validationRule, dataRow.BindingGroup.BindingExpressions); e.Cancel = false; EventArgs.Cancel = false; error.ErrorContent = null; } } }
public static IObservable <EventPattern <ManipulationBoundaryFeedbackEventArgs> > ManipulationBoundaryFeedbackObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <EventHandler <ManipulationBoundaryFeedbackEventArgs>, ManipulationBoundaryFeedbackEventArgs>(h => This.ManipulationBoundaryFeedback += h, h => This.ManipulationBoundaryFeedback -= h)); }
/// <summary> /// Builds the visual tree for the column header when a new template is applied. /// </summary> protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { RootElement = e.NameScope.Find <Panel>(DATAGRIDROW_elementRoot); if (RootElement != null) { EnsureBackground(); UpdatePseudoClasses(); } bool updateVerticalScrollBar = false; if (_cellsElement != null) { // If we're applying a new template, we want to remove the cells from the previous _cellsElement _cellsElement.Children.Clear(); updateVerticalScrollBar = true; } _cellsElement = e.NameScope.Find <DataGridCellsPresenter>(DATAGRIDROW_elementCells); if (_cellsElement != null) { _cellsElement.OwningRow = this; // Cells that were already added before the Template was applied need to // be added to the Canvas if (Cells.Count > 0) { foreach (DataGridCell cell in Cells) { _cellsElement.Children.Add(cell); } } } _detailsElement = e.NameScope.Find <DataGridDetailsPresenter>(DATAGRIDROW_elementDetails); if (_detailsElement != null && OwningGrid != null) { _detailsElement.OwningRow = this; if (ActualDetailsVisibility && ActualDetailsTemplate != null && _appliedDetailsTemplate == null) { // Apply the DetailsTemplate now that the row template is applied. SetDetailsVisibilityInternal(ActualDetailsVisibility, raiseNotification: _detailsVisibilityNotificationPending, animate: false); _detailsVisibilityNotificationPending = false; } } _bottomGridLine = e.NameScope.Find <Rectangle>(DATAGRIDROW_elementBottomGridLine); EnsureGridLines(); _headerElement = e.NameScope.Find <DataGridRowHeader>(DATAGRIDROW_elementRowHeader); if (_headerElement != null) { _headerElement.Owner = this; if (Header != null) { _headerElement.Content = Header; } EnsureHeaderStyleAndVisibility(null); } //The height of this row might have changed after applying a new style, so fix the vertical scroll bar if (OwningGrid != null && updateVerticalScrollBar) { OwningGrid.UpdateVerticalScrollBar(); } }
public static IObservable <EventPattern <GiveFeedbackEventArgs> > GiveFeedbackObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <GiveFeedbackEventHandler, GiveFeedbackEventArgs>(h => This.GiveFeedback += h, h => This.GiveFeedback -= h)); }
public static IObservable <EventPattern <DependencyPropertyChangedEventArgs> > FocusableChangedObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <DependencyPropertyChangedEventHandler, DependencyPropertyChangedEventArgs>(h => This.FocusableChanged += h, h => This.FocusableChanged -= h)); }
public static IObservable <EventPattern <SizeChangedEventArgs> > SizeChangedObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <SizeChangedEventHandler, SizeChangedEventArgs>(h => This.SizeChanged += h, h => This.SizeChanged -= h)); }
/// <summary> /// AutomationPeer for DataGridDetailsPresenter /// </summary> /// <param name="owner">DataGridDetailsPresenter</param> public DataGridDetailsPresenterAutomationPeer(DataGridDetailsPresenter owner) : base(owner) { }
public static IObservable <EventPattern <ManipulationInertiaStartingEventArgs> > ManipulationInertiaStartingObserver(this DataGridDetailsPresenter This) { return(Observable.FromEventPattern <EventHandler <ManipulationInertiaStartingEventArgs>, ManipulationInertiaStartingEventArgs>(h => This.ManipulationInertiaStarting += h, h => This.ManipulationInertiaStarting -= h)); }