WPF Management Templates - How to create a custom property?

I am currently creating the UserControl XAML library using Blend.

I created a template for my custom WPF slider type. What I would like to do now is to add a custom brush property for the control, which will make it easy to customize when developing the application interface (my slider has a background color, foreground color and sketch color). Is this possible, and if so, will it appear in the Blend interface?

I know that I can just create a loading of styles, but it seems too much to change one color ...

+4
source share
1 answer

In your UserControl code, define the dependency properties for the brushes you want to use in your template.

public static readonly DependencyProperty ThumbnailBrushProperty = DependencyProperty.Register("Command", typeof (Brush), typeof (YourControl), new PropertyMetadata(default(Brush))); 

This property will appear in the VS and Blend constructor in the Miscellaneous section.

If you understand correctly, you have created a ControlTemplate for your custom slider control. If so, you can use the property from the template by binding to it by binding the template:

UPDATE

Ok, so you are creating a template for a standard slider control. Have you considered the definition of brushes that you use as ThumbnailBrush etc. In a resource, refer to this resource dictionary in the resource dictionary that contains your slider template and just uses them from the template? In Blend, you could change it in the Resources tab.

+3
source

Source: https://habr.com/ru/post/1481915/


All Articles