我正在尝试为我的Windows应用商店应用实施自定义设置。我有用户控件,例如UserControlAppBarColors.xaml:
<UserControl x:Name="userControlAppBarColor"
x:Class="Visits.UserControlAppBarColors"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Popup x:Name="popupAppBarColors" IsLightDismissEnabled="True"
Closed="PopupAppBarColors_OnClosed" HorizontalAlignment="Right" Width="345">
<Popup.Transitions>
<TransitionCollection>
<PaneThemeTransition/>
</TransitionCollection>
</Popup.Transitions>
<Grid Name="gridAppBarColors" Background="Brown" Width="345">
<StackPanel VerticalAlignment="Top" Margin="21,30,0,0" Orientation="Horizontal">
<StackPanel>
<Button Content="Go Back" Click="BackButton_Click" />
<TextBlock Text="App Bar Color" TextWrapping="Wrap" MaxWidth="144"
FontWeight="Normal" Style="{StaticResource SubheaderTextBlockStyle}" Margin="-2,-2,0,0" />
</StackPanel>
<StackPanel Margin="13,0,0,0">
<StackPanel Orientation="Horizontal">
<Canvas Background="Aqua" Width="20" Height="20"
VerticalAlignment="Center" Tapped="CanvasColor_Tapped"></Canvas>
<TextBlock Text="Aqua" VerticalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Canvas Background="Black" Width="20" Height="20"
VerticalAlignment="Center"></Canvas>
<TextBlock Text="Black" VerticalAlignment="Center"></TextBlock>
</StackPanel>
. . .
根据Adam Nathan的书,在第503-507页,我已将此代码添加到App.xaml.cs:
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested;
}
private void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs
spcreArgs)
{
spcreArgs.Request.ApplicationCommands.Add(new SettingsCommand(1, "App Bar Color",
OnSettingsCommand));
. . .
}
// Finish this; see Nathan p. 504-507
private void OnSettingsCommand(Windows.UI.Popups.IUICommand command)
{
int id = (int) command.Id;
switch (id)
{
case 1:
break;
. . .
}
}
...这是MainPage.xaml(在&#34; Grid&#34;声明之后的上下文中显示):
. . .
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<!--next four lines from Nathan p. 506-->
<local:UserControlAppBarColors x:Name="appBarColors" />
. . .
...但是在App.xaml.cs的switch语句中没有以下任何工作 - 全部说,&#34;无法解析符号&#34;:
// Failure 1:
case 1:
this.appBarColors.Show(command); // name from MainPage.xaml
break;
// Failure 2:
case 1:
this.userControlAppBarColor.Show(command); // name of user control from
UserControlAppBarColors.xaml
break;
// Failure 3:
case 1:
this.popupAppBarColors.Show(command); // name of user control's popup from
UserControlAppBarColors.xaml
break;
我在这里误解或误解了什么?
事实证明我的第一部分代码位于错误的地方:而不是App.xaml.cs,它需要在MainPage.xaml.cs中 - 现在它可以工作了!
顺便说一句,我的第一个想法(appBarColors.Show(command))是有效的。答案 0 :(得分:1)
您对case 1:
构造中的所有案例标签使用switch
。
使用case 2:
或适当的标签。案例标签必须是独一无二的。
答案 1 :(得分:0)
Damir Arh给出了答案here
事实证明我的第一部分代码位于错误的地方:而不是App.xaml.cs,它需要在MainPage.xaml.cs中 - 现在它可以工作了!
顺便说一句,我的第一个想法(appBarColors.Show(command))是有效的。