将MasterDetailPage的背景设置为透明

时间:2018-01-24 13:57:51

标签: c# ios iphone xamarin xamarin.forms

当我尝试将Master(MasterDetailPage)的背景颜色设置为透明时,它会保持白色。

基本上我想看到的是,细节页面的颜色是通过Master显示的。

FOR EXAMPLE (如果上述情况属实,则此MasterDetailPage的背景颜色为红色(是的,我知道我可以将背景颜色设置为红色,但我希望它为透明))

Master should be red

1 个答案:

答案 0 :(得分:4)

在看到TabletMasterDetailRenderer的documentation后,我们发现我们在PCL中创建的主页面或详细信息页面将添加到_masterController.View_detailController.View

因此,当我们将BackgroundColor设置为Transparent时,页面仍然会像我们看起来一样白。我们还应该设置_masterController.View' s BackgroundColor

我们可以在渲染器中找到_masterController并将其设置为:

public override void ViewWillLayoutSubviews()
{
    base.ViewWillLayoutSubviews();

    var master = ViewControllers[0];
    master.View.BackgroundColor = UIColor.Clear;

    //This is Detail ViewController
    var detail = ViewController.ChildViewControllers[1];
}

MasterDetailPage创建自定义渲染器并将此代码放入其中。