我有以下代码 -
WebBrowser bw = new WebBrowser();
Grid gr = new Grid();
gr = ((ClosableTab)tabControl1.Items[tabControl1.SelectedIndex]).Content as Grid;
Grid grc = new Grid();
grc = gr.Children[1] as Grid;
bw = grc.Children[0] as WebBrowser;
bw.Source = new Uri(txtBoxUrl.Text);
但是我能够满足我的要求,但所有元素都是硬编码的。我知道有更好的方法和一行代码。请建议一个标准代码来执行此操作。
更新
<TabControl x:Name="tabControl1" FontWeight="UltraBlack" BorderThickness="1" BorderBrush="Black" Background="LightBlue" >
<local:ClosableTab Background="LightBlue" Title="Preview" x:Name="PreviewWindow">
<Grid>
<Border Name="mask" Background="Black" CornerRadius="5"/>
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=mask}"/>
</Grid.OpacityMask>
<WebBrowser Name="webBrowser" Source="http://www.google.com" Margin="0" />
</Grid>
</Grid>
</local:ClosableTab>
<local:AddableTab Background="LightBlue">
Click '+' to add a New Tab
</local:AddableTab>
</TabControl>