[MainPage.Xaml.cs]
private ViewModel _viewModel;
public MainPage()
{
_viewModel = new ViewModel();
}
private void clickToShowPopup_Clicked(object sender, EventArgs e)
{
_viewModel.DisplayAlert("Issue", "Can't open this page", "Ok", "Cancel");
}
[ViewModel.cs]
public class ViewModel
{
private SfPopupLayout popupLayout;
public ViewModel()
{
popupLayout = new SfPopupLayout ();
}
public void DisplayAlert(string displayText, string bodyText, string accepttext,string declinetext)
{
......
popupLayout.PopupView.HeaderTitle = displayText;
popupLayout.PopupView.ContentTemplate = contentTemplateView;
popupLayout.PopupView.ShowFooter = true;
popupLayout.PopupView.ShowCloseButton = false;
popupLayout.PopupView.AutoSizeMode = AutoSizeMode.Height;
popupLayout.PopupView.AppearanceMode = AppearanceMode.TwoButton;
//// Configure our Accept button
popupLayout.PopupView.AcceptButtonText = accepttext;
popupLayout.PopupView.AcceptCommand = new Command(() =>
{
popupLayout.IsOpen = false;
});
popupLayout.PopupView.PopupStyle.AcceptButtonTextColor = Color.Black;
popupLayout.PopupView.PopupStyle.AcceptButtonBackgroundColor = Color.White;
// Configure our Decline button
popupLayout.PopupView.DeclineButtonText = declinetext;
popupLayout.PopupView.DeclineCommand = new Command(() =>
{
popupLayout.IsOpen = false;
});
popupLayout.PopupView.PopupStyle.DeclineButtonTextColor = Color.Black;
popupLayout.PopupView.PopupStyle.DeclineButtonBackgroundColor = Color.White;
// Show the popup and wait for user to close
popupLayout.IsOpen = true;
}
}
|
<ContentPage.Content>
<Grid>
<Button x:Name="Button" Text="Login"/>
<ListView x:Name="listView" IsVisible="false">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout HeightRequest="40">
<Label Margin="10,7,0,0" Text="{Binding}" FontSize="16" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<busyindicator:SfBusyIndicator x:Name="busyindicator" AnimationType="Battery" ViewBoxWidth="50" IsBusy="{Binding IsBusy}" IsVisible="{Binding IsVisible}" ViewBoxHeight="50" TextColor="Maroon" />
</Grid>
</ContentPage.Content> |
<ContentPage.Content> <Grid> <Grid.RowDefinitions> <RowDefinition Height="50" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Button x:Name="Button" Text="Login" IsVisible="true" Grid.Row="0"/> <ListView x:Name="listView" IsVisible="false" Grid.Row="1"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout HeightRequest="40"> <Label Margin="10,7,0,0" Text="{Binding}" FontSize="16" /> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> <busyindicator:SfBusyIndicator x:Name="busyindicator" AnimationType="Battery" ViewBoxWidth="50" IsBusy="{Binding IsBusy}" IsVisible="{Binding IsVisible}" ViewBoxHeight="50" TextColor="Maroon" /> </Grid> </ContentPage.Content>
..
DataTemplate contentTemplateView = new DataTemplate(() =>
{
StackLayout stack = new StackLayout();
busyIndicator = new SfBusyIndicator();
busyIndicator.IsBusy = true;
stack.Children.Add(busyIndicator);
return stack;
});
…
}
} |
private SfPopupLayout _popupLayout; private SfBusyIndicator _busyIndicator;
protected void ShowBusy(bool show) { //TODO putting this in try catch because there is an error depending on page lifecycle try { DataTemplate contentTemplateView = new DataTemplate(() => { StackLayout stack = new StackLayout(); _busyIndicator = new SfBusyIndicator(); _busyIndicator.ViewBoxHeight = 100; _busyIndicator.ViewBoxWidth = 100; _busyIndicator.IsBusy = true; stack.Children.Add(_busyIndicator); return stack; }); _popupLayout.PopupView.HeaderTitle = string.Empty; _popupLayout.PopupView.ContentTemplate = contentTemplateView; _popupLayout.PopupView.ShowHeader = false; _popupLayout.PopupView.PopupStyle.BorderColor = Color.Transparent; _popupLayout.PopupView.ShowFooter = false; _popupLayout.PopupView.ShowCloseButton = false; _popupLayout.PopupView.AutoSizeMode = AutoSizeMode.Height; _popupLayout.PopupView.BackgroundColor = Color.Transparent; _popupLayout.IsOpen = show; } catch (Exception e) { Console.WriteLine(e.Message); //Crashes.TrackError(e); } }