c# - 如何将 XAML 转换为纯 C#?

标签 c# xaml xamarin.forms

我在 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>

如何保持绑定(bind)和更改 MasterDetailPage.Detail 的能力?

我不得不删除 ListView.ItemTemplate 声明,因为 SO 不允许我发布如此大量的代码。猜猜我得到答案后不会太难弄明白。

最佳答案

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);

关于c# - 如何将 XAML 转换为纯 C#?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42336530/

相关文章:

xamarin - 在 Xamarin 中,如何缩放图像而不使其占用与未缩放时相同的空间?

xamarin - .Net Standard 2.0 与 Realm 3.4.0 'could not resolve reference' Xamarin 表单

c# - 聚合根通过ID引用另一个聚合根,如何使用RavenDB保持完整性?

c# - Windows 服务的设计模式 - C#

c# - 如何将 UserControl 的 KeyBinding 传递给其父控件?

xaml - 如何禁用 ListView 悬停和平铺效果?

wpf - 链接到表示 3D 模型的自包含 XAML 中的外部纹理文件

java - Xamarin Forms java.exe"退出代码 1 (ProGuard)

c# - C#中的FileStream StreamReader问题

c# - 使 AddOrUpdate 仅更改某些属性