2012-08-05 49 views
0

我已经为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); 
} 
} 

像下面的浏览器有它。 enter image description here

任何人都可以帮助我吗?谢谢你的帮助!

回答

0

使用数据透视页面,并将轻击事件处理函数(类似于您的TabMenuItem_Click)关联到轻触标题上的轻击手势。

或简单地使用带有标题的数据透视页面作为1,2,3,4根据您的问题。在与事件pivot_selectionchanged相关联的事件处理程序中检查数据透视表索引,并相应地完成您的工作。

我希望这是你要找的,否则请解释一下你的问题进一步

+0

不,我不希望它是一个枢轴。我想要上面像wp7 IE或UC浏览器正在使用创建新标签。我已将图片添加到我的帖子中。 – 2012-08-06 13:53:36

+0

本地浏览器不支持此UC。你将不得不创建这个自定义的UC,并点击按钮/项目将激活该控件 或者您可以使用弹出控件并在类似的激情中设计它 – 2012-08-07 09:54:27

+0

我知道我必须创建自己的用户控件,但是新手用户控制,这就是为什么我只需要交易或类似于上述的任何样本。 – 2012-08-07 14:39:06

0

如果你仍然想创建一个用户控件有没有这么强硬。在您的项目文件夹中添加新的项目作为Windows手机用户控制。在创建的新页面中,根据需要输入用户界面的xaml代码(这与任何其他xaml页面相似)及其在代码后面的行为。

在您的炫魅

添加以下代码行
<电话:的PhoneApplicationPage的xmlns:意见= “CLR的命名空间:ProjectName.NameSpace”>

则指可以控制使用此语句 <观点:控件> </views:controlName>

我希望这有助于。让我知道如果你需要别的东西

相关问题