Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[WinRT/UWP] Do not allow IsPresented use in Split mode on desktop (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldipietro authored and rmarinho committed Mar 3, 2017
1 parent bc13d3c commit b53ccf0
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
@@ -0,0 +1,104 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 51236, "[WinRT/UWP] Setting a MasterDetailPage's IsPresented to false should not be allowed in Split mode", PlatformAffected.WinRT)]
public class Bugzilla51236 : TestMasterDetailPage
{
protected override void Init()
{
var listView = new ListView
{
ItemsSource = new string[] { "A", "B", "C" },
ItemTemplate = new DataTemplate(() =>
{
var cell = new ViewCell();
cell.View = new StackLayout
{
Children =
{
new Label { Text = "Click to set IsPresented to false" }
}
};
return cell;
}),
};

IsPresented = false;
listView.ItemTapped += (s, e) =>
{
IsPresented = false;
listView.SelectedItem = null;
Detail = new ContentPage
{
Title = "Detail",
Content = new StackLayout
{
Children =
{
new Button
{
Text = "Set IsPresented to true",
Command = new Command(() => IsPresented = true)
}
}
}
};
};

Master = new ContentPage
{
Title = "Master",
Content = new StackLayout
{
Children =
{
listView,
new Button
{
Text = "Set MasterBehavior to Popover",
Command = new Command(() =>
{
MasterBehavior = MasterBehavior.Popover;
IsPresented = false;
})
},
new Button
{
Text = "Set MasterBehavior to Split",
Command = new Command(() => MasterBehavior = MasterBehavior.Split)
},
new Button
{
Text = "Set MasterBehavior to SplitOnLandscape",
Command = new Command(() => MasterBehavior = MasterBehavior.SplitOnLandscape)
},
}
}
};

Detail = new ContentPage
{
Title = "Detail",
Content = new StackLayout
{
Children =
{
new Button
{
Text = "Set IsPresented to true",
Command = new Command(() => IsPresented = true)
}
}
}
};
}
}
}
Expand Up @@ -172,6 +172,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla47923.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla48236.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla47971.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51236.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51238.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla51642.xaml.cs">
<DependentUpon>Bugzilla51642.xaml</DependentUpon>
Expand Down
7 changes: 6 additions & 1 deletion Xamarin.Forms.Platform.UAP/MasterDetailPageRenderer.cs
Expand Up @@ -163,7 +163,7 @@ protected virtual void OnElementChanged(ElementChangedEventArgs<MasterDetailPage

protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == MasterDetailPage.IsPresentedProperty.PropertyName)
if (e.PropertyName == MasterDetailPage.IsPresentedProperty.PropertyName || e.PropertyName == MasterDetailPage.MasterBehaviorProperty.PropertyName)
UpdateIsPresented();
else if (e.PropertyName == "Master")
UpdateMaster();
Expand Down Expand Up @@ -286,6 +286,11 @@ void UpdateDetailTitle()

void UpdateIsPresented()
{
// Ignore the IsPresented value being set to false for Split mode on desktop and allow the master
// view to be made initially visible
if (Device.Idiom == TargetIdiom.Desktop && Control.IsPaneOpen && Element.MasterBehavior != MasterBehavior.Popover)
return;

Control.IsPaneOpen = Element.IsPresented;
}

Expand Down
8 changes: 8 additions & 0 deletions Xamarin.Forms.Platform.WinRT/MasterDetailPageRenderer.cs
Expand Up @@ -168,7 +168,10 @@ protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEv
else if (e.PropertyName == MasterDetailPage.IsPresentedProperty.PropertyName)
UpdateIsPresented();
else if (e.PropertyName == MasterDetailPage.MasterBehaviorProperty.PropertyName)
{
UpdateBehavior();
UpdateIsPresented();
}
else if (e.PropertyName == Page.TitleProperty.PropertyName)
UpdateTitle();
}
Expand Down Expand Up @@ -276,6 +279,11 @@ void UpdateBounds(Windows.Foundation.Size constraint, bool isPresented)

void UpdateIsPresented()
{
// Ignore the IsPresented value being set to false for Split mode on desktop and allow the master
// view to be made initially visible
if ((Device.Idiom == TargetIdiom.Desktop || Device.Idiom == TargetIdiom.Tablet) && _container.IsMasterVisible && !Element.IsPresented && Element.MasterBehavior != MasterBehavior.Popover)
return;

UpdateBehavior();

bool isPresented = !GetIsMasterAPopover() || Element.IsPresented;
Expand Down

0 comments on commit b53ccf0

Please sign in to comment.