public LockPage() { BindingContext = new LockViewModel(); CodeLabel.SetBinding(Label.TextProperty, "Code.Text"); NumberGrid = new Grid { VerticalOptions = LayoutOptions.FillAndExpand, RowDefinitions = { new RowDefinition {Height = new GridLength(ButtonWidth, GridUnitType.Absolute)}, new RowDefinition {Height = new GridLength(ButtonWidth, GridUnitType.Absolute)}, new RowDefinition {Height = new GridLength(ButtonWidth, GridUnitType.Absolute)} }, ColumnDefinitions = { new ColumnDefinition {Width = new GridLength(ButtonWidth, GridUnitType.Absolute)}, new ColumnDefinition {Width = new GridLength(ButtonWidth, GridUnitType.Absolute)}, new ColumnDefinition {Width = new GridLength(ButtonWidth, GridUnitType.Absolute)} } }; NumberGrid.Children.Add(Buttons[0], 0, 1); NumberGrid.Children.Add(Buttons[1], 1, 1); NumberGrid.Children.Add(Buttons[2], 2, 1); NumberGrid.Children.Add(Buttons[3], 0, 2); NumberGrid.Children.Add(Buttons[4], 1, 2); NumberGrid.Children.Add(Buttons[5], 2, 2); NumberGrid.Children.Add(Buttons[6], 0, 3); NumberGrid.Children.Add(Buttons[7], 1, 3); NumberGrid.Children.Add(Buttons[8], 2, 3); // Accomodate iPhone status bar. Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); MainStackLayout = new StackLayout() { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { CodeLabel, NumberGrid }, }; // Build the page. Content = MainStackLayout; }
public LockPage() { NavigationPage.SetHasNavigationBar(this, false); BindingContext = new LockViewModel(); sec = 30; rest = 00; milliSec = 30000; _advancedTimer = Resolver.Resolve<IAdvancedTimer>(); _advancedTimer.initTimer(1000, (sender, args) => { sec--; Device.BeginInvokeOnMainThread(() => { SecLabel.Text = sec.ToString(); }); if (sec == 5) Device.BeginInvokeOnMainThread(() => { SecLabel.TextColor = Color.Red; }); Debug.WriteLine(milliSec); if (sec == 0) { _advancedTimer.stopTimer(); GameCompleted(); } }, true); NumberGrid = new Grid { VerticalOptions = LayoutOptions.CenterAndExpand, RowSpacing = 10, ColumnSpacing = 10 }; _lockService = new LockService(); NumberGrid.Children.Add(Buttons[0], 0, 1); NumberGrid.Children.Add(Buttons[1], 1, 1); NumberGrid.Children.Add(Buttons[2], 2, 1); NumberGrid.Children.Add(Buttons[3], 0, 2); NumberGrid.Children.Add(Buttons[4], 1, 2); NumberGrid.Children.Add(Buttons[5], 2, 2); NumberGrid.Children.Add(Buttons[6], 0, 3); NumberGrid.Children.Add(Buttons[7], 1, 3); NumberGrid.Children.Add(Buttons[8], 2, 3); NumberGrid.Children.Add(Buttons[9], 0, 4); NumberGrid.Children.Add(Buttons[10], 1, 4); NumberGrid.Children.Add(Buttons[11], 2, 4); // Accomodate iPhone status bar. Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); ClockStackLayout = new StackLayout { Orientation = StackOrientation.Vertical, Children = { SecLabel } }; if (Device.Idiom == TargetIdiom.Phone) MainStackLayout = new StackLayout { VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { ClockStackLayout, ResponsLabel, LabelAndEraseLayout, NumberGrid }, Padding = new Thickness(0, 0, 0, 10) }; if (Device.Idiom == TargetIdiom.Tablet) { var rightStack = new StackLayout { VerticalOptions = LayoutOptions.CenterAndExpand, Children = { ClockStackLayout, ResponsLabel, LabelAndEraseLayout, NumberGrid }, Padding = new Thickness(0, 0, 0, 10) }; var width = Resolver.Resolve<IDevice>().Display.Width; var leftImage = new Image { Source = "iconlogo1024x500.png", Aspect = Aspect.AspectFill, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, WidthRequest = width/2 }; var leftContentView = new ContentView { Content = leftImage, MinimumWidthRequest = Width/2, BackgroundColor = Color.White }; var leftStackLayout = new StackLayout { Orientation = StackOrientation.Vertical, Children = { leftContentView, new Button { Text = "Reset", BorderColor = Color.Green, BorderRadius = 5, Command = new Command(() => { Reset(); }), VerticalOptions = LayoutOptions.End } }, VerticalOptions = LayoutOptions.FillAndExpand }; MainStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, Children = { // leftStackLayout, rightStack } }; } Content = MainStackLayout; //_advancedTimer.startTimer(); }