2 回答
TA贡献1852条经验 获得超1个赞
我发现单击按钮时很难保持条目的焦点。
我给你写了一个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 关注
- 87 浏览
添加回答
举报