2 回答

TA貢獻1852條經(jīng)驗 獲得超1個贊
我發(fā)現(xiàn)單擊按鈕時很難保持條目的焦點。
我給你寫了一個WorkAroud,當詞條是 的時候Unfocused,用apreviousEntry記錄這個詞條:
public partial class MainPage : ContentPage
{
public Entry previousEntry;
public MainPage()
{
InitializeComponent();
first.Unfocused += (object sender, FocusEventArgs e) => {
previousEntry = (Entry)sender;
};
second.Unfocused += (object sender, FocusEventArgs e) => {
previousEntry = (Entry)sender;
};
third.Unfocused += (object sender, FocusEventArgs e) => {
previousEntry = (Entry)sender;
};
}
private void Button_Clicked(object sender, EventArgs e)
{
Button button = (Button)sender;
string pressed = button.Text;
if (previousEntry != null)
{
previousEntry.Text += pressed;
}
}
}
在Xaml中:
<StackLayout>
<!-- Place new controls here -->
<Button Text="click me" Clicked="Button_Clicked" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
<Entry x:Name="first" Text="1+" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
<Entry x:Name="second" Text="2+" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
<Entry x:Name="third" Text="3+" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
</StackLayout>
讓我知道它是否有效。
- 2 回答
- 0 關注
- 112 瀏覽
添加回答
舉報