[英]Setting the background of a MasterDetailPage to be transparent
When I try to set the background color of the Master (of the MasterDetailPage) to transparent, it stays white. 当我尝试将Master(MasterDetailPage)的背景颜色设置为透明时,它会保持白色。
Basically what I would want to see, is that the color from the detail page is shown through the Master. 基本上我想要看到的是,细节页面的颜色是通过Master显示的。
FOR EXAMPLE (If the above were true, then the background color of this MasterDetailPage would be red (Yes I know I can just set the background colour as red, but I want it to be transparent )) 例如 (如果以上都是真的,那么这个MasterDetailPage的背景颜色将是红色的(是的,我知道我可以将背景颜色设置为红色,但我希望它是透明的 ))
After seeing the TabletMasterDetailRenderer's documentation , we can find that the master or detail page which we create in PCL will be added on the _masterController.View
and _detailController.View
. 在看到TabletMasterDetailRenderer的文档后 ,我们可以发现我们在PCL中创建的主页面或详细页面将添加到
_masterController.View
和_detailController.View
。
So when we set its BackgroundColor
to Transparent
, the page will still be white as what we look. 因此,当我们将
BackgroundColor
设置为Transparent
,页面仍然是白色的。 We should also set the _masterController.View
's BackgroundColor
. 我们还应该设置
_masterController.View
的BackgroundColor
。
We can find the _masterController
in renderer and set it like: 我们可以在渲染器中找到
_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];
}
Create a custom renderer for MasterDetailPage
and put this code in it. 为
MasterDetailPage
创建自定义渲染器并将此代码放入其中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.