Hi all. I have a custom ClockFace UserControl which has properties to allow colors, font and hands (as a Path objects) to be changed. This is used in custom TimePicker and Clock UserControls. In these parent controls, the ClockFace properties can be set on the ClockFace object in xaml just fine. What I'm trying to do is expose these ClockFace properties so that they can be set on these two parent controls (eg. the Clock and TimePicker objects). I thought that making them Attached properties would do the trick, so I tried with one of the colour properties.
public static readonly DependencyProperty HourTicksBrushProperty = DependencyProperty.RegisterAttached("HourTicksBrush", typeof(Brush), typeof(ClockFace), new FrameworkPropertyMetadata(Brushes.Black, FrameworkPropertyMetadataOptions.AffectsRender));
public static void SetHourTicksBrush(DependencyObject element, Brush value)
{
element.SetValue(HourTicksBrushProperty, value);
}
public static Brush GetHourTicksBrush(DependencyObject element)
{
return (Brush)element.GetValue(HourTicksBrushProperty);
}
I can use this attached property in the xaml where the Clock is with: (Controls is the xml namespace)
<Controls:Clock Controls:ClockFace.HourTicksBrush="Aqua" />
It compiles just fine, but although the default value (Brushes.Black) from the attached HourTicksBrushProperty shows, the value set on the parent Clock control (Aqua) never fire the above methods or change the colour. Am I missing something?
To be clear, I would like to be able to use the above xaml on a parent control to set the HourTicksBrush property of a child ClockFace control.
Any help would be much appreciated.