Skip to content

Instantly share code, notes, and snippets.

@dansiegel
Created January 9, 2020 14:56
Show Gist options
  • Save dansiegel/5d8a31dd9b9d7d6a8da76fd327ff723e to your computer and use it in GitHub Desktop.
Save dansiegel/5d8a31dd9b9d7d6a8da76fd327ff723e to your computer and use it in GitHub Desktop.
Adding child Partial View to a Partial View
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AwesomeApp.Views"
x:Name="parent"
x:Class="AwesomeApp.Views.ViewA">
<local:ViewB ParentPage="{x:Reference parent}" />
</ContentPage>
<?xml version="1.0" encoding="utf-8" ?>
<StackLayout xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AwesomeApp.Views"
x:Name="parent"
x:Class="AwesomeApp.Views.ViewB">
<local:ViewC x:Name="childPartialView" />
</StackLayout>
using Prism.Mvvm;
using Xamarin.Forms;
namespace AwesomeApp.Views
{
public partial class ViewB
{
public static readonly BindableProperty ParentPageProperty =
BindableProperty.Create(nameof(ParentPage), typeof(Page), typeof(ViewB), null);
public ViewB()
{
InitializeComponent();
ViewModelLocator.SetAutoWirePartialView(this, ParentPage);
ViewModelLocator.SetAutoWirePartialView(childPartialView, ParentPage);
}
public Page ParentPage
{
get => (Page)GetValue(ParentPageProperty);
set => SetValue(ParentPageProperty, value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment