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());
}
精彩评论