Reputation: 7392
I have created a Popup page using Rg.Popups in Xamarin Forms. There are different variations of the popup in the application, and I would ideally want to use the same popup with different contents in it.
<?xml version="1.0" encoding="UTF-8"?>
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="CustomKeyboard.Controls.CustomPopup"
xmlns:local="clr-namespace:CustomKeyboard.Controls;assembly=CustomKeyboard"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
<StackLayout
VerticalOptions="Center"
HorizontalOptions="Center"
BackgroundColor = "#00000000"
Padding="20, 0, 20, 0">
<Frame CornerRadius = "8" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
<local:Content1 />
</Frame>
</StackLayout>
The is a content view and its static. I would need to content View to be dynamic.
So when I navigate to the CustomPopup, I should be able to specify which ContentView I need to use, and the popup need to render that specific content view. Appreciate if someone could suggest a neat way to achieve this.
Upvotes: 1
Views: 772
Reputation: 7392
I ended up with something like this and its works well for me.
I created the control just using c# (no xaml). But u could do that as well
public class PDTPopup : Rg.Plugins.Popup.Pages.PopupPage
{
public PDTPopup(ContentView view)
{
Frame frame = new Frame
{
CornerRadius = 8,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
Content = view
};
this.Content = new Xamarin.Forms.StackLayout()
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
BackgroundColor = Color.FromHex("#00000000"),
Padding = new Thickness(20, 0, 20, 0),
Children =
{
frame
}
};
}
}
and then, where i need to call the popup. I do
public Command PopupCommand
{
get
{
return new Command(async () => {
Content1Page view = new Content1Page();
await PopupNavigation.Instance.PushAsync(new CustomPopup(view));
});
}
}
Upvotes: 1