c#xamarin无法使用xamarin跨平台项目扩展Web视图

时间:2017-03-02 15:23:47

标签: c# visual-studio xamarin

Actual screenshot of the problem
在这里看到附图,我点击了4个按钮,当他们中的任何一个被点击时他们给我看了一个webview,但由于某种原因我无法展开网页视图以便它覆盖屏幕的其余部分。正如您在图片中看到的那样,webview位于一列中,按钮位于一行中。我真的很感激帮助。谢谢。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    using Xamarin.Forms;

    namespace LocalDataAccess
    {
        public partial class RecipeSites : ContentPage
        {
            public RecipeSites()
            {
                this.Content = gridlayout();
            }

            public Grid gridlayout()
            {
                BackgroundColor = Color.White;

                Button allrecipes = new Button
                {
                        BackgroundColor = Color.Transparent,
                };
                allrecipes.Clicked += new EventHandler(allrecipes_Click);
                allrecipes.Image = "alrecipe.png";

                Button delia = new Button
                {
                    BackgroundColor = Color.Transparent,

                };
                delia.Clicked += new EventHandler(delia_Click);
                delia.Image = "delia.gif";

                Button bbc = new Button
                {
                    BackgroundColor = Color.Transparent,
                };
                bbc.Clicked += new EventHandler(bbc_Click);
                bbc.Image = "bbc.jpg";

                Button food = new Button
                {
                    BackgroundColor = Color.Transparent,
                };
                food.Clicked += new EventHandler(food_Click);
                food.Image = "food.jpg";

                var grid = new Grid();
                RowDefinition gridRow1 = new RowDefinition();

                gridRow1.Height = new GridLength(7, GridUnitType.Star);
                grid.RowDefinitions.Add(gridRow1);
                grid.Children.Add(allrecipes, 0, 1);
                grid.Children.Add(delia, 1, 1);
                grid.Children.Add(bbc, 2, 1);
                grid.Children.Add(food, 3, 1);
                return grid;
            }

            public void food_Click(object sender, EventArgs e)
            {
                Grid sl = gridlayout();

                WebView webView = new WebView
                {
                    Source = new UrlWebViewSource
                    {
                        Url = " http://www.food.com/",
                    },
                    VerticalOptions = LayoutOptions.FillAndExpand,

                };
                var grid1 = new Grid()
                { VerticalOptions = LayoutOptions.FillAndExpand };
               ColumnDefinition c2 = new ColumnDefinition();
               c2.Width = new GridLength(10, GridUnitType.Star);
               grid1.ColumnDefinitions.Add(c2);
                grid1.Children.Add(webView, 3,1 );
                this.Content = sl;
            }

            public void allrecipes_Click(object sender, EventArgs e)
            {
                Grid sl = gridlayout();

                WebView webView = new WebView
                {
                    Source = new UrlWebViewSource
                    {
                        Url = "http://allrecipes.co.uk/",
                    },
                    HorizontalOptions = LayoutOptions.FillAndExpand

                };

                sl.Children.Add(webView);
                this.Content = sl;
    }

    public void delia_Click(object sender, EventArgs e)
    {
            Grid sl = gridlayout();

            WebView webView = new WebView
        {
            Source = new UrlWebViewSource
            {
                Url = "http://www.deliaonline.com/recipes",
            },
            VerticalOptions = LayoutOptions.FillAndExpand
        };
        sl.Children.Add(webView);
        this.Content = sl;
    }

    public void bbc_Click(object sender, EventArgs e)
    {
            Grid sl = gridlayout();

            WebView webView = new WebView
        {
            Source = new UrlWebViewSource
            {
                Url = "http://www.bbc.co.uk/food/recipes/",
            },
            VerticalOptions = LayoutOptions.FillAndExpand
        };
        sl.Children.Add(webView);
        this.Content = sl;
    }

    }
    }

1 个答案:

答案 0 :(得分:0)

如果您希望控件跨越多行或多列,则需要设置范围值

// add button to col 0 row 4
controlGrid.Children.Add (zeroButton, 0, 4);
// make the button span 2 columns
Grid.SetColumnSpan (zeroButton, 2);