Possible Duplicate:
C# keyword usage virtual+override vs. new
I'm trying to hide my UserControl
Content property in the following way:
public partial class Tile : UserControl
{
public new object Content
{
get { ... }
set { ... }
}
}
But when I set the Content of my UserControl it does not do anything (if I set a breakpoint it is never reached):
<my:Tile Content="The content"/>
or
<my:Tile>The content</my:Tile>
Why? How can I solve this problem?
The problem is that you aren't hiding the actual DependencyProperty, only the get/set accessor which WPF may or may not always use to set the value of the DP. WPF has optimizations that directly call DependencyObject.GetValue/SetValue instead.
Create a dependency property on your object with the name "Content" instead and then new up the get/set accessors and what you are doing should work.
I'm not sure why you would want to do this though, instead of just using the content property that is already there. It would seem to me that you are fighting the framework here and there's an easier way to do what you want.