Custom UserControl question.... [modified]
-
I have the following custom UserControl: <Setter Property="MinWidth" Value="55" /> <Setter Property="MaxWidth" Value="60" /> <Setter Property="Margin" Value="0,0,5,0" /> Here is the referenced DependencyProperty: public static DependencyProperty UICTypeLabelProperty = DependencyProperty.RegisterAttached("UICTypeLabel", typeof(string), typeof(UICControl), new PropertyMetadata(String.Empty)); public string UICTypeLabel { get { return (string)GetValue(UICTypeLabelProperty); } set { SetValue(UICTypeLabelProperty, value); } } And here is the usage: But I'm not seeing "Responsible" when the control presents itself on the display. What am I doing wrong? I am also seeing this error message in the Output window: System.Windows.Data Error: 39 : BindingExpression path error: 'UICTypeLabel' property not found on 'object' ''BasicViewContext' (HashCode=13769489)'. BindingExpression:Path=UICTypeLabel; DataItem='BasicViewContext' (HashCode=13769489); target element is 'GroupBox' (Name=''); target property is 'Header' (type 'Object') BasicView is the XAML window that is using the control. Thanks Phil -- Modified Thursday, August 26, 2010 3:11 PM
-
I have the following custom UserControl: <Setter Property="MinWidth" Value="55" /> <Setter Property="MaxWidth" Value="60" /> <Setter Property="Margin" Value="0,0,5,0" /> Here is the referenced DependencyProperty: public static DependencyProperty UICTypeLabelProperty = DependencyProperty.RegisterAttached("UICTypeLabel", typeof(string), typeof(UICControl), new PropertyMetadata(String.Empty)); public string UICTypeLabel { get { return (string)GetValue(UICTypeLabelProperty); } set { SetValue(UICTypeLabelProperty, value); } } And here is the usage: But I'm not seeing "Responsible" when the control presents itself on the display. What am I doing wrong? I am also seeing this error message in the Output window: System.Windows.Data Error: 39 : BindingExpression path error: 'UICTypeLabel' property not found on 'object' ''BasicViewContext' (HashCode=13769489)'. BindingExpression:Path=UICTypeLabel; DataItem='BasicViewContext' (HashCode=13769489); target element is 'GroupBox' (Name=''); target property is 'Header' (type 'Object') BasicView is the XAML window that is using the control. Thanks Phil -- Modified Thursday, August 26, 2010 3:11 PM
Because the GroupBox is looking for "UICTypeLabel" on its DataContext, not on the UserControl. You need to tell it where to look.
Header="{Binding UICTypeLabel,RelativeSource={RelativeSource FindAncestor,AncestorType=UserControl}}"
(Might have to use{x:Type UserControl}
in there... I forget whether it's necessary)Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels) -
Because the GroupBox is looking for "UICTypeLabel" on its DataContext, not on the UserControl. You need to tell it where to look.
Header="{Binding UICTypeLabel,RelativeSource={RelativeSource FindAncestor,AncestorType=UserControl}}"
(Might have to use{x:Type UserControl}
in there... I forget whether it's necessary)Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels)