i need my control to inherit the UIElement.IsEnabledProperty from an Ancestor of type Grid (Optionally Window or any other element i could wrap my grid with )
CS : below i override the meta data of UIElement.IsEnabledProperty and set it with Change and Coerce delegates .
static PipeControl()
{
PipeControl.IsEnabledProperty.OverrideMetadata(typeof(PipeControl), new FrameworkPropertyMetadata(false, OnIsEnabledPropertyChanged, OnIsEnabledPropertyCoerce));
}
private static void OnIsEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var isEnabled = (bool)e.NewValue;
}
private static object OnIsEnabledPropertyCoerce(DependencyObject d, object baseValue)
{
var valueSource = DependencyPropertyHelper.GetValueSource(d, PipeControl.IsEnabledProperty);
var pipeContorl = d as PipeControl;
if (pipeContorl == null) return baseValue;
return (bool)baseValue && pipeContorl.IsMyPipe;
}
XAML :
<Grid IsEnabled="{Binding IsMyCondition , Mode=OneWay}">
<game:PipeControl Grid.Row="2" />
<game:PipeControl Grid.Row="2" Grid.Column="1" />
</Grid>
each time IsMyCondition changes OnIsEnabledPropertyCoerce is called in each PipeContorl , OnIsEnabledPropertyChanged is never called , the ValueSource in OnIsEnabledProerty Coerce is "Default" (show the Coerce always gets the default false value).
i must of missed something in the manner in which i need to use Inheritance , i would expect the value source the be "Inherited" and the OnIsEnabledPropertyChanged to be called.