コード例 #1
0
        private void OnContentViewChanged()
        {
            if (!Ext.IsWinPhone())
            {
                touchView = new BoxView {
                    BackgroundColor = Color.Gray, Opacity = 0.5, IsVisible = false
                }
            }
            ;
            contentLayout.HeightRequest = 400;
            contentLayout.Children.Add(ContentView);

            if (touchView != null)
            {
                contentLayout.Children.Add(touchView);

                var tapGestureRecognizer = new TapGestureRecognizer();
                tapGestureRecognizer.Tapped += tapGestureRecognizer_Tapped;
                touchView.GestureRecognizers.Add(tapGestureRecognizer);
            }

            if (Device.OS == TargetPlatform.Android)
            {
                contentLayout.BackgroundColor = Color.White;
            }
            if ((Device.Idiom == TargetIdiom.Phone && Device.OS == TargetPlatform.Windows) || Device.OS == TargetPlatform.WinPhone)
            {
                ContentView.HeightRequest = App.ScreenHeight - 120;
                ContentView.WidthRequest  = App.ScreenWidth - 10;
            }

            if (App.Platform == Platforms.UWP && Device.Idiom == TargetIdiom.Phone)
            {
                ContentView.WidthRequest  = App.ScreenWidth - 20;
                ContentView.HeightRequest = App.ScreenHeight - 65;
                contentLayout.Padding     = new Thickness(5, 5, 0, 0);
            }
            rootLayout.Children.Clear();
            rootLayout.Children.Add(contentLayout);
            Content = rootLayout;
        }
コード例 #2
0
        public SampleListCell()
        {
            this.SetBinding(TypeProperty, "SampleType");

            var sampleName = new LabelExt {
                VerticalOptions = LayoutOptions.Center
            };

            sampleName.SetBinding(Label.TextProperty, "Title");
            sampleName.VerticalOptions = LayoutOptions.Center;
            //if (Device.OS == TargetPlatform.Windows && Device.Idiom == TargetIdiom.Phone)
            //    sampleName.HorizontalOptions = LayoutOptions.FillAndExpand;

            if (Device.Idiom == TargetIdiom.Desktop || Device.Idiom == TargetIdiom.Tablet)
            {
                sampleName.WidthRequest = 210;
            }
            sampleName.FontSize = Device.Idiom == TargetIdiom.Tablet
                ? DeviceExt.OnPlatform(15, 15, 25)
                : DeviceExt.OnPlatform(13, 13, 25);

            sampleName.VerticalOptions = LayoutOptions.Center;
            if ((Device.OS == TargetPlatform.Windows && Device.Idiom == TargetIdiom.Phone) || Device.OS == TargetPlatform.WinPhone)
            {
                sampleName.TextColor = Color.White;
                sampleName.FontSize  = 23;
            }
            else
            {
                sampleName.TextColor = Color.Black;
            }

            if (App.Platform == Platforms.UWP && Device.Idiom == TargetIdiom.Phone)
            {
                sampleName.FontSize = 15;
            }

            rootLayout = new Grid
            {
                VerticalOptions   = LayoutOptions.FillAndExpand,
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(60, GridUnitType.Absolute)
                    }
                }
            };

            if (Device.OS != TargetPlatform.Android)
            {
                rootLayout.BackgroundColor = Color.White;
            }
            sampleName.TextColor = Color.FromHex("#333D47");
            if (Device.Idiom != TargetIdiom.Phone && Device.OS == TargetPlatform.Windows)
            {
                sampleName.FontSize = 15;
                sampleName.SetBinding(Label.TextColorProperty, new Binding("ForegroundColor"));
                rootLayout.SetBinding(Layout.BackgroundColorProperty, new Binding("BackgroundColor"));
            }

            rootLayout.VerticalOptions = LayoutOptions.Center;

            if (Device.OS == TargetPlatform.Android)
            {
                rootLayout.HorizontalOptions = LayoutOptions.StartAndExpand;
            }
            else
            {
                rootLayout.HorizontalOptions = LayoutOptions.Center;
            }

            rootLayout.Children.Add(sampleName, 0, 0);

            rootLayout.Padding = DeviceExt.OnPlatform(new Thickness(15, 10, 5, 5), new Thickness(15, 10, 5, 5),
                                                      new Thickness(4, 3, 5, 3));

            if (Ext.IsWinPhone())
            {
                StackLayout stackLayout = new StackLayout
                {
                    Children        = { rootLayout },
                    BackgroundColor = Color.White,
                    Padding         = 0,
                    Spacing         = 0,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                };

                View = stackLayout;
            }
            else
            {
                View = rootLayout;
            }
        }