Вместо возврата значения bool
создайте два Command
s в YesOrNotPopup
:
public static readonly BindableProperty PrimaryCommandProperty = BindableProperty.Create(nameof(PrimaryCommand), typeof(ICommand), typeof(YesOrNotPopup));
public static readonly BindableProperty SecondaryCommandProperty = BindableProperty.Create(nameof(SecondaryCommand), typeof(ICommand), typeof(YesOrNotPopup));
public ICommand PrimaryCommand
{
get => ( ICommand ) this.GetValue ( PrimaryCommandProperty );
set => this.SetValue ( PrimaryCommandProperty , value );
}
public ICommand SecondaryCommand
{
get => ( ICommand ) this.GetValue ( SecondaryCommandProperty );
set => this.SetValue ( SecondaryCommandProperty , value );
}
и свяжите их со свойствами Command
s TapGestureRecognizer
двух Label
s.
Нужно больше гибкости в управлении?
Создать PrimaryButtonText
, SecondaryButtonText
и Message
привязываемых свойств ..
XAML с привязкой:
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
WidthRequest="60"
HeightRequest="60"
Padding="30"
x:Class="MyApp.PopupPages.YesOrNotPopup "
x:Name="ThisPopUpPage" >
<StackLayout>
<Label Text="{Binding Message, Source={Reference ThisPopUpPage}}" HorizontalOptions="CenterAndExpand"/>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Label x:Name="NoLabel" ClassId="1" Text="{Binding SecondaryButtonText, Source={Reference ThisPopUpPage}}">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SecondaryCommand, Source={Reference ThisPopUpPage}}"/>
</Label.GestureRecognizers>
</Label>
<Label x:Name="YesLabel" Text="{Binding PrimaryButtonText, Source={Reference ThisPopUpPage}}">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding PrimaryCommand, Source={Reference ThisPopUpPage}}"/>
</Label.GestureRecognizers>
</Label>
</StackLayout>
</StackLayout>
</pages:PopupPage>
Использование:
PopupNavigation.Instance.PushAsync(new YesOrNotPopup {
{
Message = "Submit your request?" ,
PrimaryButtonText = "Yes" ,
PrimaryCommand = new Command (async() =>
{
ShowLoading();
await BookingService.BookRoom(booking);
HideLoading();
}) ,
SecondaryButtonText = "No" ,
SecondaryCommand = new Command (()=> /*do nothing*/)
});