I have defined an enum in C#
public enum PointerStyle
{
Pointer,
Block,
Slider
} ;
I am using it as a dependency property on a WPF custom control
public static DependencyProperty DisplayStyleProperty =
DependencyProperty.Register("DisplayStyle", typeof(PointerStyle), typeof(Pointer), new PropertyMetadata(PointerStyle.Pointer));
public PointerStyle DisplayStyle
{
get { return (PointerStyle)GetValue(DisplayStyleProperty); }
set { SetValue(DisplayStyleProperty, value); }
}
and using it in a ControlTemplate
<Trigger Property="DisplayStyle" Value="{x:Static local:PointerStyle.Block}">
Very often, but not always, the editor underlines most of the code and shows the error "'Block' is not a valid value for property 'DisplayStype'." as shown in the following screen shot
This is in Visual Studio 2015.
At runtime, the code works perfectly.
In the design window of my test program, the control is rendered totally incorrectly.
What am I doing wrong?
What is the best way to refer to an enum value in XAML?
(I would be happy to use a TypeConverter and to define the value as a string, but I can't find a good example of how do it.)
WPF already provides built-in type conversion from string to enum types.
So you could simply write
<Trigger Value="Block" ...>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With