C# 单个页面上的多个应用程序栏
我需要一些帮助在一个页面上添加多个应用程序栏。目前我有一个页面A。在A中应该有两个应用程序条。一个用于当用户关注文本框时(这将显示所有编辑工具等),另一个用于当用户松开文本框时(这用于保存和删除等常规控制) 我不想对所有控件使用一个应用程序栏。我想要分开,这样更整洁。我知道,但为了做到这一点,我需要将其添加到App.xaml页面。是否有一种方法可以将其添加到页面a的xaml或任何代码中以使其工作。我尝试了以下方法,但没有成功:C# 单个页面上的多个应用程序栏,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我需要一些帮助在一个页面上添加多个应用程序栏。目前我有一个页面A。在A中应该有两个应用程序条。一个用于当用户关注文本框时(这将显示所有编辑工具等),另一个用于当用户松开文本框时(这用于保存和删除等常规控制) 我不想对所有控件使用一个应用程序栏。我想要分开,这样更整洁。我知道,但为了做到这一点,我需要将其添加到App.xaml页面。是否有一种方法可以将其添加到页面a的xaml或任何代码中以使其工作。我尝试了以下方法,但没有成功: <phone:PhoneApplicationPage.Res
<phone:PhoneApplicationPage.Resources>
<shell:ApplicationBar x:Key="AppBar1" IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
<shell:ApplicationBar x:Key="AppBar2" IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1" />
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2" />
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1" />
<shell:ApplicationBarMenuItem Text="MenuItem 2" />
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.Resources>
谢谢 很简单,将它们添加到页面的资源中:
<phone:PhoneApplicationPage.Resources>
<shell:ApplicationBar x:Key="AppBar1" IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1" Click="Button1_Click" />
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1" Click="MenuItem1_Click" />
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
<shell:ApplicationBar x:Key="AppBar2" IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1" Click="Button1_Click" />
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2" Click="Button2_Click" />
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1" Click="MenuItem1_Click" />
<shell:ApplicationBarMenuItem Text="MenuItem 2" Click="MenuItem2_Click" />
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.Resources>
您应该记住在哪里定义资源。请注意,在中,资源已连接到整个应用程序:
Application.Current.Resources["AppBar1"]);
如果您在App.xaml中将您的资源定义为Application.Resources
,那么您的代码将起作用-然后您定义的AppBar将可用于所有页面
在您的代码中定义了PhoneApplicationPage.Resources
,因此它们仅可用于该特定页面。您可以在此页面上使用它们,例如:
ApplicationBar = this.Resources["AppBar1"] as ApplicationBar;
@Ahmed.C-尝试在代码中更改应用程序,如下所示:ApplicationBar=this.Resources[“AppBar1”]作为ApplicationBar;(此-与PhoneApplicationPage有关)@Romasz成功了!把它写下来作为一个答案,我会给它打上记号:)为什么我在这里发布之前在VisualStudio中花时间测试它,你会说它不起作用?