tho*_*iel 1 xamarin xamarin.forms
我想DisplayAlert
在我的ContentPage中使用,通过单击"确定"按钮显示要确认的简单消息,所以我的第三个参数是"OK".这意味着:我不需要第二个按钮的第四个参数.现在我发现Windows Phone和Android之间存在差异:
我想知道:我是否只需编写一个DependencyService来显示只有一个按钮的警报?
WinPhone运行时版本:v4.0.30319 Android支持版本:v5
更新Dylan的评论:
async void OnMyEvent(object sender, EventArgs args)
{
await DisplayAlert("Message 1", "Hello Android!", "OK"); // <- works on Android but doesn't compile on WinPhone
await DisplayAlert("Message 2", "Hello WinPhone!", "OK", null); // <- works on WinPhone but throws a null pointer exception on Android
}
Run Code Online (Sandbox Code Playgroud)
您可以将"确定"按钮作为取消按钮,如下所示:
var result = await DisplayAlert("Message", "Hello there!", null, "OK");
Run Code Online (Sandbox Code Playgroud)
这将显示一个只有一个OK按钮的警告框.然后检查是否result
是false
.如果是,则表示单击了"确定"按钮.
例如
var result = await DisplayAlert("Message", "Hello there!", null, "OK");
if (!result) //result is false
//Do something
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1740 次 |
最近记录: |