入口单元格失去对 xamarin 表单中按钮按下的关注

我有一些按钮,当按下它时就像键盘一样,它必须填充一个聚焦的输入字段。但它不起作用,因为按下按钮会导致条目失去焦点。谁能给我一个解决这个问题的提示?


    private void Button_Clicked(object sender, EventArgs e)

    {   Button button = (Button)sender;

        string pressed = button.Text;

        if (this.FirstDigit.IsFocused)

        {

            this.FirstDigit.Text += pressed;

        }and so on ...


慕田峪7331174
浏览 115回答 2
2回答

小怪兽爱吃肉

我发现单击按钮时很难保持条目的焦点。我给你写了一个WorkAroud,当词条是 的时候Unfocused,用apreviousEntry记录这个词条:public partial class MainPage : ContentPage{&nbsp; &nbsp; public Entry previousEntry;&nbsp; &nbsp; public MainPage()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; InitializeComponent();&nbsp; &nbsp; &nbsp; &nbsp; first.Unfocused += (object sender, FocusEventArgs e) => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; previousEntry = (Entry)sender;&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; second.Unfocused += (object sender, FocusEventArgs e) => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; previousEntry = (Entry)sender;&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; third.Unfocused += (object sender, FocusEventArgs e) => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; previousEntry = (Entry)sender;&nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; }&nbsp; &nbsp; private void Button_Clicked(object sender, EventArgs e)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; Button button = (Button)sender;&nbsp; &nbsp; &nbsp; &nbsp; string pressed = button.Text;&nbsp; &nbsp; &nbsp; &nbsp; if (previousEntry != null)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; previousEntry.Text += pressed;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;}在Xaml中:<StackLayout>&nbsp; &nbsp; <!-- Place new controls here -->&nbsp; &nbsp; <Button Text="click me" Clicked="Button_Clicked"&nbsp; HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>&nbsp; &nbsp; <Entry x:Name="first" Text="1+" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>&nbsp; &nbsp; <Entry x:Name="second" Text="2+" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>&nbsp; &nbsp; <Entry x:Name="third" Text="3+" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/></StackLayout>让我知道它是否有效。

繁星coding

我会打电话entry.Focus();用那种方法让它工作。
打开App,查看更多内容
随时随地看视频慕课网APP