views:

84

answers:

1

I have a dependency property and a callback.

public static readonly DependencyProperty IsBusyProperty =
            DependencyProperty.Register("IsBusy", typeof(bool), 
            typeof(TabHost), new PropertyMetadata(false, IsBusyPropertyChangedCallback));

private static void IsBusyPropertyChangedCallback(DependencyObject o,
                   DependencyPropertyChangedEventArgs args)
{
/* .. */
}

Assume property value is false and someone is setting again it to false, the callback never happens. Is there any way to force the callback to happen always?

+2  A: 

No, there isn't. Silverlight calls the PropertyChangedCallback only if the property has actually changed. Silverlight reasons that if your TabHost was non-busy before, and it's non-busy now, then nothing has changed and you don't want to be pestered with a spurious notification.

If you're depending on getting notifications for staying in the same state, you may want to re-examine your design: for example, invoking a RefreshBusyState method rather than relying on the change notification. Your use case revolves around user code setting the property (rather than the Silverlight DP system setting the property). So the first question is does this need to be a dependency property? Unless you need to bind, style or animate it, it could be a normal CLR property, and you can raise spurious change notifications in the setter if you so choose. If it does need to be a DP but you want to know when user code sets it, then make the CLR property setter private, and provide a SetBusyState method instead: again, that method can perform whatever change logic you want. That method won't run when Silverlight rebinds, styles or animates the property, but it will run if client code explicitly sets it.

itowlson