I have been working with attached properties and came up with an interesting theoretical question. I know that if I want to set an attached property through XAML, I use the format:
<control ownerClass.propertyName="some value"/>
My question is, what happens if I derive a class from “ownerClass”. For example, if I define the following class:
class MyGrid : Grid {
}
Tried to set it through XAML as follows
<MyGrid>
<Button MyGrid.Row = "0">Bla Bla</Button>
</MyGrid>
But the intellisense did not let me. Once I used the proper namespace on the attached property, it worked.
Also, it allowed me to do this:
<MyGrid>
<Button Grid.Row = "0">Bla Bla</Button>
</MyGrid>
It makes sense, of course, since the Row attached property is a static member of the Grid class and was defined by it. The only problem here is that the users of my new class get to know that it was derived from Grid, and that this specific property was defined by the ancestor. To me it seems like this is implementation details that I would not like to expose to the users of my class.
Is there a way to get WPF to hide the fact that this attached property was actually defined by the superclass?
Thanks,
Kobi
I’m not sure I see the problem. I tried this out and it works. Also, the intellisence was working. What .NET version are you using and what version of VisualStudio? I tried this with .NET 4.0 and VS2010