2017-03-02 139 views
0

Actual screenshot of the problem
见附件形象在这里,我对任何人都点击了,他们告诉我网页视图时,网格4个按键,但由于某些原因,我扩展网络视图无法展开网页视图,以便覆盖屏幕的其余部分。正如你在图片中看到的,webview是在一个列中,而按钮是在一行中。我真的很感激帮助。谢谢。C#xamarin无法使用xamarin跨平台项目

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; 
    } 

    } 
    } 

回答

0

你需要,如果你想控制跨越多个行或列

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

去不起作用设定的跨度值? –

+0

你能否更新你的问题以显示修改后的代码? – Jason

+0

它现在在工作,感谢您的帮助。 –