Created
January 9, 2020 14:56
-
-
Save dansiegel/5d8a31dd9b9d7d6a8da76fd327ff723e to your computer and use it in GitHub Desktop.
Adding child Partial View to a Partial View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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