按钮不响应第一次单击

时间:2016-05-28 07:54:24

标签: wpf win-universal-app uwp windows-10-universal windows-10-mobile

我有用户输入个人电话号码的页面。当TextBox获得焦点时,显示虚拟键盘,但是当用户完成键入电话号码并单击“下一步”绿色按钮(对于屏幕截图中的俄语语言抱歉)时,首先单击“通过”按钮并关闭键盘并且只有下一次单击才会激活click事件。 任何想法如何解决? 也许页面焦点状态存在一些问题,但老实说我不知道​​。

enter image description here

更新 这是我页面的XAML

<Grid x:Name="LayoutRoot" Style="{StaticResource GeneralAppBackground}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    // Control to show the loading state
    <controls:LoadingPageState x:Name="LoadingGrid" Visibility="Collapsed" Grid.RowSpan="3" Canvas.ZIndex="1" TitleOfOperation="Проверка существования кошелька..." />
    <Grid Style="{StaticResource GeneralAppHeaderStyle}">
        <TextBlock Text="Введите номер телефона" FontWeight="Normal" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource PageHeaderTextBlockStyle}" />
    </Grid>
    <Grid Grid.Row="1">
        <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="20,0,20,0">
            <TextBlock x:Uid="Greeting" Foreground="#979797" TextAlignment="Center" Margin="0,0,0,10" />
            <Grid Margin="0,0,0,5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBox Grid.Column="0" PlaceholderText="+7" FontSize="18" BorderThickness="0,0,0,2" BorderBrush="#979797" Background="Transparent" IsReadOnly="True" Margin="0,0,10,0" Template="{StaticResource DefaultTextBoxStyle}"/>
                <TextBox x:Name="UserPhoneNumberInput" Grid.Column="1" IsTextPredictionEnabled="False" IsSpellCheckEnabled="False" PlaceholderText="777 123 12 12" FontSize="18" BorderThickness="0,0,0,2" BorderBrush="#979797" MaxLength="10" Background="Transparent" InputScope="TelephoneNumber" Template="{StaticResource DefaultTextBoxStyle}" TextChanged="UserPhoneNumberInput_TextChanged" />
            </Grid>
            <TextBlock x:Name="HintText" TextWrapping="WrapWholeWords" Foreground="#979797" TextAlignment="Center">
                Ваш телефон будет использоваться в качестве номера кошелька
            </TextBlock>
        </StackPanel>
    </Grid>
    <Button x:Name="NextStepButton" Grid.Row="2" IsEnabled="False" Content="Далее" VerticalAlignment="Bottom" Style="{StaticResource WideGreenButtonStyle}" Click="NextStepButton_Click" />
</Grid>

这是按钮点击事件的C#代码

private void NextStepButton_Click(object sender, RoutedEventArgs e)
    {
        if (!UserPhoneNumberInput.Text.All(Char.IsDigit) || UserPhoneNumberInput.Text.Length == 0)
        {
            NotifyUser.ShowWrongPhoneNumberFormatMessage();
            return;
        }

        phoneNumber = Helpers.FormatNumber(UserPhoneNumberInput.Text);

        // Activate the ContentLoading ring
        LoadingGrid.Visibility = Visibility.Visible;
        LoadingGrid.IsProgressRingActive = true;

        CheckNumber(phoneNumber);
    }

在这里,如果重要的是我的“LoadingGrid”的XAML

<Grid x:Name="LayoutRoot" Background="#CC000000">
    <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
        <ProgressRing x:Name="ProgressRing" Width="50" Height="50" Foreground="White" IsActive="{x:Bind IsProgressRingActive, Mode=TwoWay}" />
        <TextBlock x:Name="OperationTitle" Text="{x:Bind TitleOfOperation, Mode=TwoWay}" TextAlignment="Center" FontSize="18" Foreground="White" Margin="0,20,0,0" />
    </StackPanel>
</Grid>

1 个答案:

答案 0 :(得分:3)

这是设计的。

当您单击 NextStepButton 按钮时, UserPhoneNumberInput TextBox会失去焦点,然后键盘会自动消失。最有可能,但根据您的自定义布局模板, NextStepButton 也会稍微向下移动。当您释放鼠标按钮时(假设您正在使用模拟器),那时 NextStepButton 不在那里。这就是为什么它不会触发 Click 事件。如您所知,按钮的默认 ClickMode ClickMode.Release 。我最近遇到了完全相同的问题。

您可以尝试将 IsTabStop =“False”添加到按钮属性中以解决此问题。