Problem with WPF IsEnabled updating on property changed.

Problem with WPF IsEnabled updating on property changed.

Old forum URL: forums.lhotka.net/forums/t/9246.aspx


Curelom posted on Wednesday, July 21, 2010

I have a BusinessObject "SoxControl"

This control has owner which can signoff the control, or clear the signoff.

An admin can also signoff or clear a signoff of a control as well as change the owner of the control.

I have 2 buttons which signoff or clear the signoff and are to enable/disable approriate with whether the user has rights and the state of the signoff.

The problem is that WPF doesn't seem to be updating the IsEnabled property on a change, even though I have walked through the code and watched it call the PropertyHasChanged on the approriate properties.  Any ideas on where I go from here, or is there a completely different way to handle this that makes more sense?  - Using CSLA 4 RC0

Thanks

 <Button Name="btnSignoff" Content="Signoff" Margin="0,0,5,0"
                                IsEnabled="{Binding Path=CanOwnerSignoff, 

   ValidatesOnExceptions=true, NotifyOnValidationError=true, 

   UpdateSourceTrigger=PropertyChanged}" />
<csla:TriggerAction x:Name="trgSignoff" 

                    TargetControl="{Binding ElementName=btnSignoff}" Height="0" Width="0"
                    TriggerEvent="Click" DataContext="{Binding Path=CurrentItem, Source={StaticResource soxControlListViewModelViewSource}}" 
                   
 MethodName="OwnerSignoff"/>
                        
<Button Name="btnClearSignoff" Content="Clear" 
 
 IsEnabled="{Binding Path=CanClearOwnerSignoff, ValidatesOnExceptions=true, 

  NotifyOnValidationError=true,

  UpdateSourceTrigger=PropertyChanged}"/>

<csla:TriggerAction x:Name="trgClearSignoff" 

TargetControl="{Binding ElementName=btnClearSignoff}" Height="0" Width="0"
                        TriggerEvent="Click" 
                       
 DataContext="{Binding Path=CurrentItem, 

Source={StaticResource soxControlListViewModelViewSource}}" 
                   
 MethodName="ClearOwnerSignoff"/>

private bool UserOwnerSignoff {
    get { 
         return !String.IsNullOrEmpty(GetProperty<string>(ControlOwnerSignoffProperty)); }
  }
}
 public static PropertyInfo<bool> CanOwnerSignoffProperty = RegisterProperty<bool>(c => c.CanOwnerSignoff);
       /// <summary>
        /// Determines if OwnerSignoff can be completed.
        /// If user is an Admin, or the control owner and control is not already signed off then true
        /// </summary>        
        public bool CanOwnerSignoff {
            get {
                SoxIdentity currentUserIdentity = ApplicationContext.User.Identity as SoxIdentity;
                if ((currentUserIdentity.IsInRole("ADMIN"
               || currentUserIdentity.Name == GetProperty<string>(ControlOwnerProperty)) 
                        && UserOwnerSignoff)
                    return true;
                else
                    return false;
            }            
        }

        public static PropertyInfo<bool> CanClearOwnerSignoffProperty = RegisterProperty<bool>(c => c.CanClearOwnerSignoff);
        /// <summary>
        /// Determines if OwnerSignoff can be cleared.
        /// If user is an Admin, or the control owner and control is already signed off then true
        /// </summary>
        public bool CanClearOwnerSignoff {
            get {
                SoxIdentity currentUserIdentity = ApplicationContext.User.Identity as SoxIdentity;
                if ((currentUserIdentity.IsInRole("ADMIN"
               || currentUserIdentity.Name == GetProperty<string>(ControlOwnerProperty)) 
                    && !UserOwnerSignoff)
                    return true;
                else
                    return false;            
            }           
        }      
#endregion // Properties

        #region Methods
        /// <summary>
        /// Signoff the control
        /// </summary>
        public void OwnerSignoff() {
            string ownerSignoff = GetProperty<string>(ControlOwnerSignoffProperty);
            SoxIdentity currentUserIdentity = ApplicationContext.User.Identity as SoxIdentity;

            if (currentUserIdentity.IsInRole("ADMIN"
               || currentUserIdentity.Name == GetProperty<string>(ControlOwnerProperty)) {
                SetProperty<string>(ControlOwnerSignoffProperty, currentUserIdentity.UserId);
                SetProperty<System.DateTime?>(DateCertifiedProperty, new DateTime?(DateTime.Today));
            }

            PropertyHasChanged(CanOwnerSignoffProperty);
            PropertyHasChanged(CanClearOwnerSignoffProperty);
        }
        
        /// <summary>
        /// Clear the certification signoff
        /// </summary>
        public void ClearOwnerSignoff() {
            string ownerSignoff = GetProperty<string>(ControlOwnerSignoffProperty);
            SetProperty<string>(ControlOwnerSignoffProperty, null);
            SetProperty<System.DateTime?>(DateCertifiedProperty, new DateTime?());
            
            PropertyHasChanged(CanOwnerSignoffProperty);
            PropertyHasChanged(CanClearOwnerSignoffProperty);
        }
        #endregion

Curelom replied on Wednesday, July 21, 2010

Nevermind, it just started working.

Copyright (c) Marimer LLC