Amazing User
Amazing User

Reputation: 3563

TextBox.InputBindings blocks user input

I show timer on TextBox. When I press it, I call method which pause the timer and then I need to be able to write data to the TextBox using keyboard (then I will parse this numeric data to the format hh/mm/ss). But with block TextBox.InputBindings I can't write anything to it, it blocks user input. How can I solve it?

<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();
    }
}

Upvotes: 0

Views: 56

Answers (1)

Justin CI
Justin CI

Reputation: 2741

Try removing Command Binding

        private ICommand _TextBoxPress;
        public ICommand TextBoxPress
        {
            get { return _TextBoxPress; }
            set { _TextBoxPress = value; this.NotifyPropertyChanged("TextBoxPress"); }
        }

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

Upvotes: 1

Related Questions