UWP XAML 设置按位(标志)枚举值
UWP XAML setting bitwise (flag) enum value
我正在寻找一种在 UWP XAML 中设置按位(标志)枚举值的方法。 WPF 方法(逗号分隔,"value1,value2,value3")似乎不起作用。
非常感谢任何指点!
编辑 1
看来逗号分隔的语法是正确的。我遇到的问题与特定枚举有具体关系。我正在尝试使用以下 属性:
在 InkCanvas class 上公开 CoreInputDeviceTypes
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;
}
事物的 XAML 方面是:
<local:CustomInkCanvas Width="2000" Height="2000" x:Name="inkCanvas" InputDeviceTypes="Mouse,Pen">
</local:CustomInkCanvas>
失败并出现以下异常:
Failed to assign to property 'App5.CustomInkCanvas.InputDeviceTypes'. [Line: 14 Position: 101]'
就这样
<Rectangle ManipulationMode="TranslateX,TranslateY" />
应该可以。
更新
CoreInputDeviceTypes
有这个 : unit
阻止绑定工作。
[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
}
一个简单的解决方法是在没有它的情况下创建自己的枚举,并在 属性 更改的回调中进行映射。
我正在寻找一种在 UWP XAML 中设置按位(标志)枚举值的方法。 WPF 方法(逗号分隔,"value1,value2,value3")似乎不起作用。
非常感谢任何指点!
编辑 1
看来逗号分隔的语法是正确的。我遇到的问题与特定枚举有具体关系。我正在尝试使用以下 属性:
在 InkCanvas class 上公开 CoreInputDeviceTypes 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;
}
事物的 XAML 方面是:
<local:CustomInkCanvas Width="2000" Height="2000" x:Name="inkCanvas" InputDeviceTypes="Mouse,Pen">
</local:CustomInkCanvas>
失败并出现以下异常:
Failed to assign to property 'App5.CustomInkCanvas.InputDeviceTypes'. [Line: 14 Position: 101]'
就这样
<Rectangle ManipulationMode="TranslateX,TranslateY" />
应该可以。
更新
CoreInputDeviceTypes
有这个 : unit
阻止绑定工作。
[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
}
一个简单的解决方法是在没有它的情况下创建自己的枚举,并在 属性 更改的回调中进行映射。