0
在PCL項目中,使用Xamarin格式,我將開關位置設置爲開/關,這將調用切換事件。在切換切換事件中有確認提醒,如果用戶選擇「否」,它將再次將切換設置爲先前狀態。 問題是,如果按「否」,切換的方法會被再次調用。我想阻止方法調用。如何將開關值設置爲開/關並防止在Xamarin表格中切換方法調用
Switch switcher = new Switch
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
};
switcher.Toggled += switcher_Toggled;
void switcher_Toggled(object sender, ToggledEventArgs e)
{
Device.BeginInvokeOnMainThread(async() =>
{
bool alert;
if (this._isConnectionStatusOpen == true)
{
alert = await DisplayAlert("Close ", "Are you sure you want to close connection?", "Yes", "No");
}
else
{
alert = await DisplayAlert("Open", "Are you sure you want to Open connection?", "Yes", "No");
}
if (alert != true)
{
Switch thisSender = (Switch)sender;
thisSender.IsToggled = !thisSender.IsToggled;
}
});
}
有沒有簡單的方法來實現它?
您使用的是MVVM框架嗎? –
不,我沒有使用MVVM。它的PCL項目與Xamarin.Forms – Samir
你爲什麼不設置'On'屬性? –