如何在 XAML 中为 TextEdit 绑定 Mask 属性?

How to bind Mask properties for TextEdit in XAML?

我正在尝试在我的 WPF 项目中设置一个 TextEdit 框,但是我的掩码有一些问题。

XAML:

     <dxe:TextEdit x:Name="dxTextEdit" 
                   Height="23" MinWidth="200" Width="Auto"
                   HorizontalAlignment="Right"
                   Text="{Binding Value, Mode=TwoWay}"
                   MaskType="RegEx" 
                   MaxLength="{Binding InputLength}"
                   Mask="{Binding Mask, Mode=TwoWay}"
                   />

其中 Mask returns 一个字符串,如“[a-zA-Z0-9]”,InputLength returns 一个值。我不能在框中插入任何内容,或者我最多只能插入一个字符。问题是,掩码在我的 SpinEdit 框中工作得很好,编码如下:

XAML:

     <dxe:SpinEdit x:Name="dxSpinEdit" 
                   Height="23" MinWidth="200" Width="Auto"
                   HorizontalAlignment="Right"
                   Text="{Binding Value, Mode=TwoWay}"
                   MaskType="Numeric"
                   IsFloatValue="{Binding FloatValue}"
                   MinValue="{Binding MinValue}"
                   MaxValue="{Binding MaxValue}"
                   Mask="{Binding Mask, Mode=TwoWay}" 
                   MaxLength="{Binding Path=InputLength}"
                   MaskShowPlaceHolders="{Binding ShowPlaceHolder}"
                   InvalidValueBehavior="WaitForValidValue"
                   MaskUseAsDisplayFormat="True"
                   AllowRoundOutOfRangeValue="True"
                   />

Where Mask returns strings like "d", "n0"

我需要能够绑定输入长度和在 xaml 中定义我的掩码的字符串。任何想法我做错了什么?我浏览了大部分 devexpress 论坛,发现了类似这样的内容: Mask="([a-zA-Z0-9]|\s){0,31}" 但它不允许我修改长度或正则表达式。

在掩码模式下,TextEdit.MaxLength 属性 不可操作,必须设置为 0。在这种情况下,最终用户可以输入的字符数由编辑器的掩码指定. 查看 Quantifiers section of Mask Type: Extended Regular Expressions 帮助文章以了解如何创建合适的遮罩:

[a-zA-Z0-9]{0,_} // you should replace _ with the exact length value