for (int i = 0; i < list.Count; i++) {
ds = new Discription();
PivotItem pivotItem = new PivotItem();
pivotItem.Header = list.ElementAt(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());
}
调用Web浏览器控件时发生错误 在它位于可视树中之前,您无法调用WebBrowser方法。
答案 0 :(得分:4)
订阅Webbrowser控件的Loaded事件,并将导航代码移动到加载的处理程序。
替换
行wb.NavigateToString(list.ElementAt(i).Detail.ToString());
带
var address = list.ElementAt(i).Detail.ToString();
wb.Loaded += (sender, e) => { wb.NavigateToString(address); }
答案 1 :(得分:0)
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());
}