【问题标题】:Button needs to be clicked twice due to textbox lost focus由于文本框失去焦点,按钮需要单击两次
【发布时间】:2018-01-24 06:17:19
【问题描述】:

我有一个包含 UpdateSourceTrigger = LostFocus 的文本框。

当我在文本框中输入内容并立即单击按钮时,按钮单击事件不会触发。我认为文本框只是失去了对按钮的关注。当我再次点击按钮时,它会触发点击事件。

如何解决这个问题?

这是我的 XAML 代码:

<TextBox x:Name="ApText"
                         Width="135"
                         Margin="0,4,0,0"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Top"
                         Text="{Binding Value, Mode=TwoWay, NotifyOnValidationError=True, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
                         TextWrapping="Wrap"
                         Validation.ErrorTemplate="{DynamicResource UI.ErrorTemplateStyle}" />

<Button
                    Width="100"
                    MinWidth="60"
                    MinHeight="40"
                    Margin="0,8,0,0"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Bottom"
                    Command="{Binding SaveCommand}"
                    Content="Save" />

【问题讨论】:

标签: c# wpf mvvm lost-focus updatesourcetrigger


【解决方案1】:

为此找到了解决方案。 刚刚将 Button 的 Clickmode 更改为 Press。瞧它的工作原理。

更新代码:

<Button
                    Width="100"
                    MinWidth="60"
                    MinHeight="40"
                    Margin="0,8,0,0"
                    ClickMode="Press"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Bottom"
                    Command="{Binding SaveCommand}"
                    Content="Save" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多