TextBox.InputBindings阻止用户输入

时间:2019-05-06 06:39:46

标签: c# wpf xaml mvvm

我在TextBox上显示计时器。当我按下它时,我调用了暂停计时器的方法,然后我需要能够使用键盘将数据写入到TextBox中(然后,我会将这些数字数据解析为hh / mm / ss格式)。但是使用块TextBox.InputBindings时,我什么都不能写,它阻止了用户输入。我该怎么解决?

<Grid>
    <TextBox Name="textTimeTop" HorizontalAlignment="Left" Height="35" Margin="20,20,0,0"
             TextWrapping="Wrap" VerticalAlignment="Top" Width="120" FontSize="24"
             Text="{Binding TestTimer.TimeFormat, UpdateSourceTrigger=PropertyChanged}">
        <TextBox.InputBindings>
            <MouseBinding Command="{Binding Path=TextBoxPress}" MouseAction="LeftClick"/>
        </TextBox.InputBindings>
    </TextBox>
</Grid>

ViewModel

public class UserInteractiton
{
    public UserInteractiton()
    {
        TextBoxPress = new DelegateCommand(TextBoxGotFocus);
    }

    public ICommand TextBoxPress { get; private set; }

    private void TextBoxGotFocus(object obj)
    {
        TestTimer.StopTimer();
    }
}

1 个答案:

答案 0 :(得分:1)

尝试删除命令绑定

match
相关问题