maui-linux/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issu.../Bugzilla31602.cs

131 строка
3.4 KiB
C#

using System;
using Xamarin.Forms.CustomAttributes;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
#if UITEST
using Xamarin.UITest;
using Xamarin.UITest.iOS;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls
{
[Preserve (AllMembers = true)]
[Issue (IssueTracker.Bugzilla, 31602, "not possible to programmatically open master page after iPad landscape -> portrait rotation, also tests 31664")]
public class Bugzilla31602 : TestMasterDetailPage
{
protected override void Init ()
{
BindingContext = new MasterViewModel1 ();
((MasterViewModel1)BindingContext).MasterPage = this;
Master = new SidemenuPage ();
Detail = new NavigationPage (new DetailPage1 (Master as SidemenuPage));
}
public class SidemenuPage : ContentPage
{
public SidemenuPage ()
{
Title = "Side";
Icon = "menuIcon.png";
var lbl = new Label { Text = "SideMenu" };
var btn = new Button { Text = "Menu Opener" };
btn.SetBinding (Button.CommandProperty, new Binding ("OpenSideMenuCommand"));
var stackpanel = new StackLayout { VerticalOptions = LayoutOptions.Center };
stackpanel.Children.Add (btn);
stackpanel.Children.Add (lbl);
Content = stackpanel;
}
public void ChangeIcon() {
Icon = "bank.png";
}
}
public class DetailPage1 : ContentPage
{
SidemenuPage _sideMenu;
public DetailPage1 (SidemenuPage menu)
{
_sideMenu = menu;
Title = "Detail";
var btns = new Button { Text = "Change Icon" };
btns.Clicked += (object sender, EventArgs e) => {
_sideMenu.ChangeIcon();
};
var btn = new Button { Text = "Sidemenu Opener" };
btn.SetBinding (Button.CommandProperty, new Binding ("OpenSideMenuCommand"));
Content = new StackLayout { Children = { btns, btn} };
}
}
[Preserve (AllMembers = true)]
public class MasterViewModel1 : INotifyPropertyChanged
{
public MasterDetailPage MasterPage;
public event PropertyChangedEventHandler PropertyChanged = delegate { };
protected void OnPropertyChanged ([CallerMemberName] string propertyName = null)
{
if (PropertyChanged != null) {
PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
}
}
bool _isMenuOpen;
public bool IsMenuOpen {
get { return _isMenuOpen; }
private set {
if (_isMenuOpen != value) {
System.Diagnostics.Debug.WriteLine ("setting new sidemenu visibility flag to: " + value);
_isMenuOpen = value;
OnPropertyChanged ();
}
}
}
public ICommand OpenSideMenuCommand { get; private set; }
public MasterViewModel1 ()
{
IsMenuOpen = true;
OpenSideMenuCommand = new Command (OpenSideMenu);
}
void OpenSideMenu ()
{
IsMenuOpen = true;
MasterPage.IsPresented = IsMenuOpen;
}
}
#if UITEST
[Test]
public void Bugzilla31602Test ()
{
var appAs = RunningApp as iOSApp;
if (appAs != null && appAs.Device.IsTablet) {
RunningApp.Tap (q => q.Marked ("Sidemenu Opener"));
RunningApp.WaitForElement (q => q.Marked ("SideMenu"));
RunningApp.SetOrientationLandscape ();
RunningApp.WaitForElement (q => q.Marked ("SideMenu"));
RunningApp.SetOrientationPortrait ();
RunningApp.WaitForNoElement (q => q.Marked ("SideMenu"));
RunningApp.Tap (q => q.Marked ("Sidemenu Opener"));
RunningApp.WaitForElement (q => q.Marked ("SideMenu"));
}
}
#endif
}
}