【问题标题】:How to bind Mask properties for TextEdit in XAML?如何在 XAML 中为 TextEdit 绑定 Mask 属性?
【发布时间】:2018-11-28 22:06:38
【问题描述】:

我正在尝试在我的 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 返回一个类似“[a-zA-Z0-9]”的字符串,而 InputLength 返回一个值。我不能在框中插入任何东西,或者我最多只能插入一个字符。问题是,掩码在我的 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"
                   />

Mask 返回诸如“d”、“n0”之类的字符串

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

【问题讨论】:

  • 试试[a-zA-Z0-9]+
  • @ASh 我试过了,但我什么都打不出来

标签: wpf xaml devexpress


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 2013-05-17
    相关资源
    最近更新 更多