开发者

An error is occur when i called Web browser....

开发者 https://www.devze.com 2023-03-23 18:32 出处:网络
for (int i = 0; i < list.Count; i++) { ds = new Discription(); PivotItem pivotItem = new PivotItem();
for (int i = 0; i < list.Count; i++) {
  ds = new Discription();

  PivotItem pivotItem = new PivotItem();
  pivotItem.Header = list.Eleme开发者_开发知识库ntAt(i).header.ToString();

  StackPanel sta = new StackPanel();
  WebBrowser wb = new WebBrowser();

  sta.Children.Add(wb);

  pivotItem.Content = sta;         
  Pivot_item1.Items.Add(pivotItem);
  wb.NavigateToString(list.ElementAt(i).Detail.ToString());
}

an error is occur when calling web browser control You cannot call WebBrowser methods until it is in the visual tree.


Subscribe to the Loaded event of the Webbrowser control and move your navigation code to the loaded handler.

Replace the line

wb.NavigateToString(list.ElementAt(i).Detail.ToString());

with

var address = list.ElementAt(i).Detail.ToString();
wb.Loaded += (sender, e) => { wb.NavigateToString(address); }


    for (int i = 0; i < list.Count; i++) {
        ds = new Discription();

          PivotItem pivotItem = new PivotItem();
            pivotItem.Header = list.ElementAt(i).header.ToString();

       Grid sta = new Grid();
         WebBrowser wb = new WebBrowser();
         var address = list.ElementAt(i).Detail.ToString();
          wb.Loaded += (sender, e) => { wb.NavigateToString(address); };
       sta.Children.Add(wb);

         pivotItem.Content = sta;         
         Pivot_item1.Items.Add(pivotItem);
        wb.NavigateToString(list.ElementAt(i).Detail.ToString());
         }
0

精彩评论

暂无评论...
验证码 换一张
取 消