2017-02-20 78 views
1

我在XAML中有頁面,需要它在純C#中。但無法弄清楚如何轉換它。如何將XAML轉換爲純C#?

<?xml version="1.0" encoding="utf-8" ?> 
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="xmr_cross_test.Navigation.MDPage"> 

    <MasterDetailPage.Master> 
    <ContentPage Title="Menu"> 
     <StackLayout Orientation="Vertical"> 
     <ListView x:Name="navigationDrawerList" 
        RowHeight="60" 
        SeparatorVisibility="None" 
        ItemSelected="OnMenuItemSelected"> 
     </ListView> 
     </StackLayout> 

    </ContentPage> 
    </MasterDetailPage.Master> 

    <MasterDetailPage.Detail> 
    <NavigationPage> 

    </NavigationPage> 
    </MasterDetailPage.Detail> 
</MasterDetailPage> 

如何做到保持綁定和能力改變MasterDetailPage.Detail

我不得不刪除ListView.ItemTemplate聲明,因爲SO不允許發佈如此大量的代碼。猜想在我得到答案後找出答案並不難。

回答

2
MasterDetailPage mdp = new MasterDetailPage(); 
ContentPage master = new ContentPage { Title = "Menu" }; 
StackLayout menu = new StackLayout(); 
ListView menuList = new ListView() { RowHeight = 60 }; 
menuList.ItemSelected += OnMenuItemSelected; 
ContentPage detail = new ContentPage(); 

menu.Children.Add(menuList); 
master.Content = menu; 
mdp.Master = master; 

mdp.Detail = new NavigationPage(detail);