Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
345
Very strange error
posted

I'm sure I must be doing something really simple and stupid wrong, but I can't for the life of me work it out.

For some reason, one of the columns I have defined is not binding to the underlying row.  The key and name is correct (EntityId).  And the rest of the columns bind correctly.  But the behaviour of the 'EntityId' column is quite strange.  The column uses a User Control which works correctly in all other parts of the interface.  But in the XAM Grid Templated Column it doesn't. 

I go to the AddNew Row.  I fill all of the cells.  Then when I commit the Row, the row is added to the list below, except that the EntityId is blank (null) in the newly added Row.  But in the AddNew row, the EntityId is still set with whatever value I have chosen.  On further inspection, the CellExitingEditMode is called when leaving all the other cells, but is not fired when exiting the 'EntityId' cell. 

The Column is defined as below (sorry I don't know how to format it into a fixed length font) :

 

 

 

 

 

 

 

 

 

 

 

<ig:TemplateColumn Key="EntityId" HeaderText="Symbol" IsGroupable="False" EditorVerticalContentAlignment="Center" IsSummable="False" VerticalContentAlignment="Center" >

 

 

 

 

  <ig:TemplateColumn.ItemTemplate>

 

 

 

 

    <DataTemplate>

 

 

 

 

      <local:EntitySelector EntityId="{Binding EntityId, Mode=TwoWay, UpdateSourceTrigger=Explicit}" BorderBrush="Transparent" Margin="-2,-8" />

 

 

 

 

    </DataTemplate>

 

 

 

 

  </ig:TemplateColumn.ItemTemplate>

 

 

 

 

</ig:TemplateColumn>

 

EntitySelector is defined as follows (reduced) :

 

 

 

 

 

 

 

 

 

 

 

 

 

public class EntitySelector : TextBox

{

 

 

 

// ENTITY ID

 

 

 

public int? EntityId {

 

 

 

get { return (int?)GetValue(EntityIdProperty); }

 

 

 

set { SetValue(EntityIdProperty, value);

 

 

 

var EntitySymbol = (SharedModel.Instance.EntityIdToEntitySymbol != null && SharedModel.Instance.EntityIdToEntitySymbol.ContainsKey(EntityId ?? -1)) ? SharedModel.Instance.EntityIdToEntitySymbol[EntityId] : null;

 

 

 

var NewDisplaySymbol = EntitySymbol == null ? "" : EntitySymbol.DisplaySymbol;

 

 

 

if (NewDisplaySymbol != DisplaySymbol) {

EntityType = EntitySymbol ==

 

null ? null : EntitySymbol.EntityType;

DisplaySymbol = NewDisplaySymbol;

}

}

}

 

 

 

 

// Using a DependencyProperty as the backing store for EntityId. This enables animation, styling, binding, etc...

 

 

 

public static readonly DependencyProperty

EntityIdProperty = DependencyProperty.Register("EntityId", typeof(int?), typeof(EntitySelector), new PropertyMetadata(null));

... (logic)

  • 40030
    Offline posted

    Hi, 

    It's hard to say exactly whats going on without a sample, but here are a few observations from your code. 

    1. The editing events, only work when you use the EditTemplate of a TemplateColumn. 

    2. You're using a DP for the EntitiyId, but your logic for handling when EntityId is set, is in the Setter of the property. That means your code won't get hit, when the property changes via a binding. You should always put your logic for handling the changing of a DP in the property change handler of the DP, 

    For example: 

     #region EntityId
            
            /// <summary>
            /// Identifies the <see cref="EntityId"/> dependency property. 
            /// </summary>
            public static readonly DependencyProperty EntityIdProperty = DependencyProperty.Register("EntityId", typeof(int?), typeof(EntitySelector),  new PropertyMetadata(new PropertyChangedCallback(EntityIdChanged)));
    
    		public int? EntityId
    		{
    			get { return (int?)this.GetValue(EntityIdProperty); }
    			set { this.SetValue(EntityIdProperty, value); }
    		}
    				  
    		private static void EntityIdChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
    		{ 
                // Logic for handling the changing of the property should go here. 
    		}
     

    #endregion // EntityId

    -SteveZ