AttachedProperty not propagating to children?

By default, attached properties are not inherited. You have to specify it when you define the property.

Up vote 0 down vote favorite share g+ share fb share tw.

Trying to create my own custom AttachedProperty for a WPF DependencyObject failed to actually do what I wanted it to do, and I am a bit worried that I (again) did not understand a WPF concept fully. I made a very simple test class to show where my problem lies. From the MSDN Documentation, I copied public class TestBox : TextBox { public static readonly DependencyProperty IsBubbleSourceProperty = DependencyProperty.

RegisterAttached( "IsBubbleSource", typeof(Boolean), typeof(TestBox) ); public static void SetIsBubbleSource(UIElement element, Boolean value) { element. SetValue(IsBubbleSourceProperty, value); } public static Boolean GetIsBubbleSource(UIElement element) { return (Boolean)element. GetValue(IsBubbleSourceProperty); } public Boolean IsBubbleSource { get { return (Boolean)GetValue(IsBubbleSourceProperty); } set { SetValue(IsBubbleSourceProperty, value); } } } Now, placing my new and funky TextBox into a Grid like this I expected every child that does not set the IsBubbleSource property itself to "inherit" it from its parent grid.

It does not do this; a MessageBox. Show(Test.IsBubbleSource.ToString()) shows "false". The attached property is set to true.

I checked this using an OnPropertyChanged event handler. Did I miss something? Thanks!

C# wpf xaml dependency-properties link|improve this question asked Jul 16 '10 at 11:44Jens10.7k11238 95% accept rate.

By default, attached properties are not inherited. You have to specify it when you define the property: public static readonly DependencyProperty IsBubbleSourceProperty = DependencyProperty. RegisterAttached( "IsBubbleSource", typeof(Boolean), typeof(TestBox), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.

Inherits) ).

Yeah, thats it. Thanks! I wonder what use they are if they are not inherited... – Jens Jul 16 '10 at 11:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions