UWP XAML设置按位(标志)枚举值
我正在寻找一种在UWP XAML中设置按位(标志)枚举值的方法。WPF方法(逗号分隔的“value1、value2、value3”)似乎不起作用 非常感谢您的指点 编辑1 看来逗号分隔的语法是正确的。我遇到的问题与特定的枚举有关。我正在尝试使用以下属性公开InkCanvas类上的CoreInputDeviceTypes:UWP XAML设置按位(标志)枚举值,xaml,uwp,windows-10-universal,inkcanvas,Xaml,Uwp,Windows 10 Universal,Inkcanvas,我正在寻找一种在UWP XAML中设置按位(标志)枚举值的方法。WPF方法(逗号分隔的“value1、value2、value3”)似乎不起作用 非常感谢您的指点 编辑1 看来逗号分隔的语法是正确的。我遇到的问题与特定的枚举有关。我正在尝试使用以下属性公开InkCanvas类上的CoreInputDeviceTypes: public CoreInputDeviceTypes InputDeviceTypes { get { return (CoreInp
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>
照办
<Rectangle ManipulationMode="TranslateX,TranslateY" />
一个简单的解决方法是创建自己的枚举,而不使用它,并在属性更改回调中进行映射。谢谢您的回复!看起来逗号分隔的索引是正确的。因此,我的问题是试图将InkCanvas的CoreInputDeviceTypes属性公开为自定义依赖项属性(请参见对上面原始问题的编辑)。枚举位于不同的名称空间这一事实是否与此有关?太好了,谢谢!我要试一试!uint的工作方式与XAML中的int-enum不同,这听起来确实有点傻。是的,看起来枚举类型转换器不支持
uint
:(
<Rectangle ManipulationMode="TranslateX,TranslateY" />
[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
}