首页 > 解决方案 > 禁用 IntegerUpDown 控件的文本输入 - WPF

问题描述

我有一个来自 WPF 扩展库 (Xceed) 的 IntegerUpDown 控件。我希望用户只使用向上/向下箭头输入一个值,而不能在其中输入一个值

我曾尝试使用 IsReadOnly 属性,但这也禁用了向上/向下箭头。

<xctk:IntegerUpDown  IsReadOnly="True" DisplayDefaultValueOnEmptyText="True" GotFocus="Day_GotFocus" LostFocus="Day_LostFocus" x:Name="Day" Value="{Binding DayText, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Style="{StaticResource BaseDateInputTextBoxesStyle}" Minimum="{Binding MinimumDateSelection}" Maximum="{Binding MaximumDateSelection}">
    <xctk:IntegerUpDown.Watermark>
        <TextBlock Text="Day" Foreground="{StaticResource OffsetWhiteBrush}" Margin="0,0,60,0"/>
    </xctk:IntegerUpDown.Watermark>
</xctk:IntegerUpDown>

如何禁用文本框区域,以便用户无法键入值而只能使用向上/向下箭头键?

标签: c#wpfxamlmvvmxceed

解决方案


IntegerUpDown 有一个属性可以满足您的要求:AllowTextInput="False"


推荐阅读