예제 #1
0
        private void OnAttachToDataGridRow(DataGridRow dgr)
        {
            int index = dgr.GetIndex() + 1;

            if (this.AssociatedObject != null)
            {
                this.AssociatedObject.Text = index.ToString();
            }

            // Hook into the DataGridRow
            BindingOperations.SetBinding(this, TargetProperty, new Binding("Item")
            {
                Source = dgr
            });

            // Hook into the DataGrid owner.
            DataGrid dg = dgr.FindVisualParent <DataGrid>();

            dg.RowEditEnding += DgRowEditEnding;
            var cv = CollectionViewSource.GetDefaultView(dg.ItemsSource);

            if (cv != null)
            {
                cv.CollectionChanged += this.CvCollectionChanged;
            }
        }
예제 #2
0
        /// <summary>
        /// Called when the is read only flag is changed.
        /// </summary>
        /// <param name="dependencyObject">The dependency object.</param>
        /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void OnIsReadOnlyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            DataGridRow dataGridRow = (DataGridRow)dependencyObject;
            DataGrid    dataGrid    = dataGridRow.FindVisualParent <DataGrid>();

            if (GetIsReadOnly(dataGridRow))
            {
                dataGrid.BeginningEdit += OnDataGridBeginningEdit;
            }
            else
            {
                dataGrid.BeginningEdit -= OnDataGridBeginningEdit;
            }
        }