DependencyProperty not working in derived UserControl

9826
10
05-18-2010 06:17 AM
RyanCoodey
Regular Contributor
So I have been using DependencyProperties on TemplatedControls and had no issues... I am now making a UserControl that is derived from a TemplateControl...  The class "Toolbar" is a TemplatedControl and is the base for other toolbars.  The class "DataToolbar" is a UserControl derived from "Toolbar", it adds some specific content to the base toolbar and adds a DependencyProperty for a Map control...

For the life of me I cannot get the Map property to be anything other than null, it is not binding... any ideas would be great!  Thanks... Heres a code snippet:

CodeBehind:
public partial class DataToolbar : Toolbar
{
        //Members - Dependency Properties
        protected static readonly DependencyProperty dependencyPropertyMap = DependencyProperty.Register("Map", typeof(Map), typeof(DataToolbar), null);

        //Properties
        public Map Map
        {
            get { return (Map)GetValue(dependencyPropertyMap); }
            set { SetValue(dependencyPropertyMap, value); }
        }
}


XAML:
<local:DataToolbar x:Name="DataToolbar" Map="{Binding ElementName=MyMap}" />


Thanks a lot!!!
0 Kudos
10 Replies
RyanCoodey
Regular Contributor
Cool, thanks Morten, I don't need any logic to happen, all i need is access to the Map...

Here is what I have found with some tests so far:

WORKING:
- If the DP is in a partial class derived from UserControl, it WORKS
- If the DP is in a partial class derived from another partial class which is derived from UserControl, it WORKS
- If the DP is in a class derived from ContentControl (with a style defined), it WORKS     (This is what the ESRI toolkit controls do)

NOT WORKING:
- If the DP is in a partial class derived from ContentControl (with its content as the other partial class in xaml), it does NOT work
- If the DP is in a partial class derived from another partial class which is derived from ContentControl (content in xaml), it does NOT work
- If the DP is in a partial class derived from another class which is derived from ContentControl (with a style defined), it does NOT work     (This is what I want!)

So it seems to be something with the fact that the base class is derived from ContentControl... any ideas?  Is this not possible...
0 Kudos