2

I'm looking for a way to set the bitwise (flag) enum values in UWP XAML. The WPF approach (comma separated, "value1,value2,value3") does not seem to work.

Any pointers are greatly appreciated!

edit 1

It appears comma separated syntax is correct. The issue I'm having has something specifically to do with the particular enum. I'm trying to expose CoreInputDeviceTypes on the InkCanvas class with the following property:

        public CoreInputDeviceTypes InputDeviceTypes
    {
        get { return (CoreInputDeviceTypes)GetValue(InputDeviceTypesProperty); }
        set { SetValue(InputDeviceTypesProperty, value); }
    }

    // Using a DependencyProperty as the backing store for InputDeviceTypes.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty InputDeviceTypesProperty =
        DependencyProperty.Register("InputDeviceTypes", typeof(CoreInputDeviceTypes), typeof(CustomInkCanvas), new PropertyMetadata(CoreInputDeviceTypes.Touch, new PropertyChangedCallback(OnInputDeviceChanged)));

    private static void OnInputDeviceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        (d as CustomInkCanvas).InkPresenter.InputDeviceTypes = (CoreInputDeviceTypes)e.NewValue;
    }

With XAML side of things being:

<local:CustomInkCanvas Width="2000" Height="2000" x:Name="inkCanvas" InputDeviceTypes="Mouse,Pen">
        </local:CustomInkCanvas>

That fails with the follwoing exception:

Failed to assign to property 'App5.CustomInkCanvas.InputDeviceTypes'. [Line: 14 Position: 101]'
Nick Goloborodko
  • 2,883
  • 3
  • 21
  • 38

1 Answers1

1

Just do

<Rectangle ManipulationMode="TranslateX,TranslateY" />

It should work.


Update

CoreInputDeviceTypes has this : unit that prevents binding from working.

[Flags]
public enum CoreInputDeviceTypes : uint
{
    //
    // Summary:
    //     No input.
    None = 0,
    //
    // Summary:
    //     Expose touch input events.
    Touch = 1,
    //
    // Summary:
    //     Expose pen input events.
    Pen = 2,
    //
    // Summary:
    //     Expose mouse input events.
    Mouse = 4
}

An easy workaround is to create your own enum without it, and do the mapping in your property changed callback.

Justin XL
  • 38,763
  • 7
  • 88
  • 133
  • Thanks for reply! It appears the comma separated index is correct. – Nick Goloborodko Aug 09 '17 at 21:52
  • So my issue specifically is trying to expose CoreInputDeviceTypes property of the InkCanvas as a custom Dependency Property (see edits to the original question above). Could the fact that the Enum is in a different namespace have anythign to do with it? – Nick Goloborodko Aug 09 '17 at 22:19
  • 1
    Perfect, thank you! I'll give that a go! It does sounds a bit silly that uint aren't working the same way as int enums in XAML. – Nick Goloborodko Aug 09 '17 at 22:28
  • 1
    Yeah, looks like the enum type converter doesn't support `uint`. :( – Justin XL Aug 09 '17 at 22:33