问题
So for Android when the master page of a master-detail page is shown the master page is covered with a "black dim" view so it is easy to differentiate the two pages with the eye. In iOS the detail page is not dimmed so it is tougher to differentiate the views. Is there a way to overlay the details page with a BoxView or Frame that is "black translucent" so it dims the page in similar fashion to Android. I have tried many different colors and opacities of a box view but they all completely cover the screen and you can't "see through them". Any ideas? Or better solutions? Even if it is a customer renderer for the BoxView that will work. I just need color ideas/settings to make it see through.
回答1:
Sample here: https://github.com/jgold6/XamarinSupportSamples/tree/master/XForms-TestShadingiOSDetailPage
Here's the code in case the link ever breaks:
MasterDetailPage mdPage;
Color origContentBgColor;
Color origPageBgColor;
public App()
{
mdPage = new MasterDetailPage();
mdPage.IsPresentedChanged += async (object sender, EventArgs e) => {
if (Device.OS == TargetPlatform.iOS) {
if (mdPage.IsPresented) {
var currentPage = (DetailPage)((NavigationPage)mdPage.Detail).CurrentPage;
origPageBgColor = currentPage.BackgroundColor;
origContentBgColor = currentPage.Content.BackgroundColor;
currentPage.BackgroundColor = Color.Black;
currentPage.Content.FadeTo(0.5);
if (currentPage.Content.BackgroundColor == Color.Default) {
currentPage.Content.BackgroundColor = Color.White;
}
}
else {
var currentPage = (DetailPage)((NavigationPage)mdPage.Detail).CurrentPage;
currentPage.BackgroundColor = origPageBgColor;
currentPage.Content.BackgroundColor = origContentBgColor;
currentPage.Content.FadeTo(1.0);
}
}
};
mdPage.Master = new MasterPage(){Title = "Master Page"};
mdPage.Detail = new NavigationPage( new DetailPage());
// The root page of your application
MainPage = mdPage;
}
回答2:
I just changed the order of FadeTo()
method to be the last command and the dark black effect is gone!
await currentPage.Content.FadeTo(0.5);
来源:https://stackoverflow.com/questions/38598863/xamarin-dim-page-master-detail-page