我已经为wp7创建了一个web浏览器应用程序。我在应用程序栏菜单项中添加了6个标签。但现在我想分别在用户控制页面中的这6个选项卡,如果我点击选项卡2或任何选项卡上,它应该现在工作。如何使用这些标签的用户控件
MainPage.xaml中
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBox x:Name="UrlTextBox"
KeyDown="UrlTextBox_KeyDown" />
<Grid x:Name="BrowserHost"
Grid.Row="1" />
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="1"
Click="TabMenuItem_Click" />
<shell:ApplicationBarMenuItem Text="2"
Click="TabMenuItem_Click" />
<shell:ApplicationBarMenuItem Text="3"
Click="TabMenuItem_Click" />
<shell:ApplicationBarMenuItem Text="4"
Click="TabMenuItem_Click" />
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
MainPage.xaml.cs中
public partial class MainPage : PhoneApplicationPage
{
private const int NumTabs = 4;
private int currentIndex;
private string[] urls = new string[NumTabs];
private WebBrowser[] browsers = new WebBrowser[NumTabs];
public MainPage()
{
InitializeComponent();
ShowTab(0);
}
private void ShowTab(int index)
{
this.currentIndex = index;
UrlTextBox.Text = this.urls[this.currentIndex] ?? "";
if (this.browsers[this.currentIndex] == null)
{
WebBrowser browser = new WebBrowser();
this.browsers[this.currentIndex] = browser;
BrowserHost.Children.Add(browser);
}
for (int i = 0; i < NumTabs; i++)
{
if (this.browsers[i] != null)
{
this.browsers[i].Visibility = i == this.currentIndex ? Visibility.Visible : Visibility.Collapsed;
}
}
}
private void UrlTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
Uri url;
if (Uri.TryCreate(UrlTextBox.Text, UriKind.Absolute, out url))
{
this.urls[this.currentIndex] = UrlTextBox.Text;
this.browsers[this.currentIndex].Navigate(url);
}
else
MessageBox.Show("Invalid url");
}
}
private void TabMenuItem_Click(object sender, EventArgs e)
{
int index = Int32.Parse(((ApplicationBarMenuItem)sender).Text) - 1;
ShowTab(index);
}
}
像下面的浏览器有它。
任何人都可以帮助我吗?谢谢你的帮助!
不,我不希望它是一个枢轴。我想要上面像wp7 IE或UC浏览器正在使用创建新标签。我已将图片添加到我的帖子中。 – 2012-08-06 13:53:36
本地浏览器不支持此UC。你将不得不创建这个自定义的UC,并点击按钮/项目将激活该控件 或者您可以使用弹出控件并在类似的激情中设计它 – 2012-08-07 09:54:27
我知道我必须创建自己的用户控件,但是新手用户控制,这就是为什么我只需要交易或类似于上述的任何样本。 – 2012-08-07 14:39:06