Forum Xamarin.Forms

MasterDetailPage, Use Master and Detail from constructed parameters in XAML?

ChaseFlorellChaseFlorell CAInsider, University mod
edited July 2015 in Xamarin.Forms

I'm using the Dependency Injection pattern throughout my app (not service location), and in doing so, I never new up a Page(), but instead I just add the page to the parent's constructor.

public class MyMDPage : MasterDetailPage
    public MyMDPage(MyDetailPage myDetailPage, MyMasterPage, myMasterPage) 
        _myMasterPage = myMasterPage;
        _myDetailPage = myDetailPage;
        Master = _myMasterPage;
        Detail = _myDetailPage;

Now I realize that this is splitting hairs, but I'd really like to use _myMasterPage and _myDetailPage in the XAML

<?xml version="1.0" encoding="UTF-8" ?>

        <!-- How Do I bring in _myMasterPage variable 
             so that I don't need to set it in C#?-->

    <NavigationPage BarBackgroundColor="{StaticResource BaseBlue}" 
                    BackgroundColor="{StaticResource BaseBlue}" 
                    BarTextColor="{StaticResource LightBlue}" >
        <OnIdiom x:TypeArguments="FileImageSource">

       <!-- How Do I bring in _myDetailPage variable 
             so that I don't need to set it in C#?-->


If you're wondering why I inject the page instead of newing it up, it's because each of those pages also use DI and therefore also have constructor parameters.

Is there any way to do what I'm looking for?

site note: I was thinking it would be through a StaticResource or something along those lines, but I just don't understand those bits well enough.

Best Answer


  • ChaseFlorellChaseFlorell CAInsider, University mod

    This does make sense, and I do want to avoid the need for a DataTemplate. So I suppose I'll leave it as is.

Sign In or Register to comment.