UWP 'Style' properties not found by Visual Studio 'Edit Additional Templates'

96 views Asked by At

Using the Document Outline pane in Visual Studio you can right-click a ListBox instance and the presented menu has an option that can be used to generate styles for the exposed style properties of the ListBox. You can see this below inside the red rectangle: -

enter image description here

I have created my own control and exposed a Style typed property. I want Visual Studio to discover my property and provide the same functionality. But it does not work even when I mark the class with the StyleTypedProperty attribute.

Here is a minimal example of the code for a class: -

[StyleTypedPropertyAttribute(Property = "Example", StyleTargetType = typeof(Button))]
public sealed class ExampleControl : Control
{
    public static readonly DependencyProperty ExampleStyleProperty = 
        DependencyProperty.Register(
            "ExampleStyle", 
            typeof(Style), 
            typeof(ExampleControl), 
            new PropertyMetadata(null, OnExampleStyleChanged));

    public ExampleControl()
    {
        this.DefaultStyleKey = typeof(ExampleControl);
    }

    public Style ExampleStyle
    {
        get { return GetValue(ExampleStyleProperty) as Style; }
        set { SetValue(ExampleStyleProperty, value); }
    }

    private static void OnExampleStyleChanged(DependencyObject sender, 
                                              DependencyPropertyChangedEventArgs args)
    {
    }
}
0

There are 0 answers