public static UnboundDataItemNode GetUnboundDataItemNode(object dataItem, out UnboundDataItem unboundDataItem) { lock (UnboundDataItem.UnboundDataItems) { UnboundDataItemNode current = UnboundDataItem.UnboundDataItems.FirstNode; while (current != null) { object currentDataItem = current.DataItem; unboundDataItem = current.UnboundDataItem; if (!current.IsAlive) { UnboundDataItemNode next = current.Next; UnboundDataItem.UnboundDataItems.Remove(current); current = next; continue; } if (object.Equals(currentDataItem, dataItem)) { return(current); } current = current.Next; } unboundDataItem = new UnboundDataItem(dataItem); UnboundDataItemNode unboundDataItemNode = new UnboundDataItemNode(unboundDataItem); UnboundDataItem.UnboundDataItems.Add(unboundDataItemNode); return(unboundDataItemNode); } }
public static UnboundDataItemNode GetUnboundDataItemNode( object dataItem, out UnboundDataItem unboundDataItem ) { lock( UnboundDataItem.UnboundDataItems ) { UnboundDataItemNode current = UnboundDataItem.UnboundDataItems.FirstNode; while( current != null ) { object currentDataItem = current.DataItem; unboundDataItem = current.UnboundDataItem; if( !current.IsAlive ) { UnboundDataItemNode next = current.Next; UnboundDataItem.UnboundDataItems.Remove( current ); current = next; continue; } if( object.Equals( currentDataItem, dataItem ) ) return current; current = current.Next; } unboundDataItem = new UnboundDataItem( dataItem ); UnboundDataItemNode unboundDataItemNode = new UnboundDataItemNode( unboundDataItem ); UnboundDataItem.UnboundDataItems.Add( unboundDataItemNode ); return unboundDataItemNode; } }
public void SetValue(object component, object value) { if (component is EmptyDataItem) { throw new InvalidOperationException("An attempt was made to set a value on an empty data item."); } UnboundDataItem unboundDataItem = component as UnboundDataItem; if (unboundDataItem != null) { component = unboundDataItem.DataItem; } bool isReadOnly = (this.OverrideReadOnlyForInsertion.HasValue && this.OverrideReadOnlyForInsertion.Value) ? false : this.IsReadOnly; if (isReadOnly) { throw new InvalidOperationException("An attempt was made to set a read-only property."); } this.SetValueCore(component, value); }
internal static UnboundDataItem GetUnboundDataItem(object dataItem) { if (dataItem == null) { return(s_empty); } var value = dataItem as UnboundDataItem; if (value != null) { return(value); } lock ((( ICollection )s_collection).SyncRoot) { if (!s_collection.TryGetValue(dataItem, out value)) { value = new UnboundDataItem(dataItem); s_collection.Add(dataItem, value); } return(value); } }
public UnboundDataItemNode(UnboundDataItem unboundDataItem) { if (unboundDataItem == null) { throw new ArgumentNullException("unboundDataItem"); } m_weakUnboundDataItem = new WeakReference(unboundDataItem); }
internal void RefreshUnboundItemProperty(object component) { if (m_unboundItems.Count <= 0 || (component == null)) { return; } var unboundDataItem = UnboundDataItem.GetUnboundDataItem(component); if (unboundDataItem == null) { return; } var dataItem = unboundDataItem.DataItem; if ((dataItem == null) || (dataItem is EmptyDataItem)) { return; } State state; if (m_dataItems.TryGetValue(dataItem, out state) && (state.Refreshing || state.Suspended)) { return; } m_dataItems.Add(dataItem, new State(true, false)); try { foreach (var item in m_unboundItems) { item.Refresh(unboundDataItem); } } finally { state = m_dataItems[dataItem]; if (state.Suspended) { m_dataItems[dataItem] = new State(false, true); } else { m_dataItems.Remove(dataItem); } } }
private void SetCellDataContextAnimated(bool hideContent) { object dataContext = this.DataContext; UnboundDataItem unboundDataItemContext = this.UnboundDataItemContext; bool isNewContext; foreach (Cell cell in this.CreatedCells) { Cell.AssignDataContext(cell, dataContext, unboundDataItemContext, cell.ParentColumn, out isNewContext); // We must refresh the Displayed template // since ShouldDisplayEditor always return // false when an EmptyDataItem is detected cell.RefreshDisplayedTemplate(); } if (hideContent) { this.ApplyAnimationClock(Row.CellContentOpacityProperty, null); this.SetValue(Row.CellContentOpacityProperty, 0d); } else { m_fadeInAnimation.From = 0d; m_fadeInAnimation.To = 1d; m_fadeInAnimation.Duration = TimeSpan.FromMilliseconds(TableflowView.GetRowFadeInAnimationDuration(DataGridControl.GetDataGridContext(this))); if (m_opacityAnimationClock != null) { m_opacityAnimationClock.Controller.Pause(); m_opacityAnimationClock.Completed -= this.OpacityAnimationClock_Completed; m_opacityAnimationClock = null; } m_opacityAnimationClock = ( AnimationClock )m_fadeInAnimation.CreateClock(true); m_opacityAnimationClock.Completed += this.OpacityAnimationClock_Completed; this.ApplyAnimationClock(Row.CellContentOpacityProperty, m_opacityAnimationClock); m_opacityAnimationClock.Controller.Begin(); } }
internal void ResumeUnboundItemPropertyChanged(object component) { if (component == null) { return; } var unboundDataItem = UnboundDataItem.GetUnboundDataItem(component); if (unboundDataItem == null) { return; } var dataItem = unboundDataItem.DataItem; if ((dataItem == null) || (dataItem is EmptyDataItem)) { return; } State state; if (!m_dataItems.TryGetValue(dataItem, out state) || !state.Suspended) { Debug.Fail("The item is not suspended."); return; } if (state.Refreshing) { m_dataItems[dataItem] = new State(true, false); } else { m_dataItems.Remove(dataItem); this.RefreshUnboundItemProperty(dataItem); } }
public object GetValue(object component) { // Since EmptyDataItemSafePropertyDescriptor ensure // to return null to avoid Binding exceptions when a // CollectionView other than the DataGridCollectionView // is used, we must return null to avoid calling // GetValueCore using null as component if ((component == null) || (component is EmptyDataItem)) { return(null); } UnboundDataItem unboundDataItem = component as UnboundDataItem; if (unboundDataItem != null) { component = unboundDataItem.DataItem; } return(this.GetValueCore(component)); }
internal void RefreshUnboundItemProperty(object component) { if (m_unboundItemPropertyCount > 0) { if (this.IsUnboundItemPropertyInRefresh(component)) { return; } if (this.IsUnboundItemPropertyChangedSuspended(component)) { return; } this.AddUnboundItemPropertyInRefresh(component); UnboundDataItem unboundDataItem; UnboundDataItem.GetUnboundDataItemNode(component, out unboundDataItem); try { foreach (DataGridItemPropertyBase itemProperty in this) { DataGridUnboundItemProperty unboundItemProperty = itemProperty as DataGridUnboundItemProperty; if (unboundItemProperty != null) { unboundItemProperty.Refresh(unboundDataItem); } } } finally { this.RemoveUnboundItemPropertyInRefresh(component); } } }
internal void SuspendUnboundItemPropertyChanged(object component) { if (component == null) { return; } var unboundDataItem = UnboundDataItem.GetUnboundDataItem(component); if (unboundDataItem == null) { return; } var dataItem = unboundDataItem.DataItem; if ((dataItem == null) || (dataItem is EmptyDataItem)) { return; } State state; bool refreshing = false; if (m_dataItems.TryGetValue(dataItem, out state)) { if (state.Suspended) { return; } refreshing = state.Refreshing; } m_dataItems[dataItem] = new State(refreshing, true); }
public UnboundDataItemNode( UnboundDataItem unboundDataItem ) { if( unboundDataItem == null ) throw new ArgumentNullException( "unboundDataItem" ); m_weakUnboundDataItem = new WeakReference( unboundDataItem ); }
internal static void AssignDataContext( Cell cell, object dataContext, UnboundDataItem unboundDataItemContext, ColumnBase parentColumn, out bool isNewDataContext ) { Column column = parentColumn as Column; if( ( column != null ) && ( column.IsBoundToDataGridUnboundItemProperty ) ) { if( unboundDataItemContext == null ) UnboundDataItem.GetUnboundDataItemNode( dataContext, out unboundDataItemContext ); dataContext = unboundDataItemContext; } // Read the LocalValue of the DataContext to avoid // getting the one inherited from the ParentRow. // This prevent the DataContext to become null // when the Cell is virtualized. object localDataContext = cell.ReadLocalValue( Cell.DataContextProperty ); if( localDataContext != dataContext ) { // The system will call Equals instead of RefEquals on the DataContext change. If Equals has been overriden and returns true, the DataContext will not be updated. // Hence setting it to null will make sure the right DataContext is used by the cell, and thus the cell content will be correctly updated. // This would not have to be done if a reference to the old DataItem was not keeped, which DataItem may not be part of the source anymore. if( object.Equals( localDataContext, dataContext ) ) { cell.DataContext = null; } cell.DataContext = dataContext; isNewDataContext = true; } else { isNewDataContext = false; } }