基本上,用户会在消息框中看到一个问题,他们选择确定(是)或取消(否),然后根据他们的选择 - 然后导航到与他们的答案相对应的下一页。
这是我不断收到的错误:“Microsoft.Phone.ni.dll 中发生了‘System.ArgumentException’类型的异常,但未在用户代码中处理”
我尝试使用 MS 网站上的示例,但每次都会使我的应用程序崩溃。
这是我的 XAML:
<phone:PhoneApplicationPage
x:Class="Grub2._0.Hot"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<TextBlock Foreground="Orange" Text="grub" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="Too hot to handle" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock FontSize="26" Foreground="Red" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="Auto" Width="Auto">
Is it hot outside?
</TextBlock>
<Button Click="hotYes" Content="Yes" HorizontalAlignment="Left" Margin="0,45,0,0" VerticalAlignment="Top" Width="135"/>
<Button Click="hotNo" Content="No" HorizontalAlignment="Left" Margin="140,45,0,0" VerticalAlignment="Top" Width="103"/>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
这是相应的c#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
namespace Grub2._0
{
public partial class Hot : PhoneApplicationPage
{
public Hot()
{
InitializeComponent();
}
private void hotYes(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("Parched.xaml", UriKind.Relative));
}
private void hotNo(object sender, RoutedEventArgs e)
{
MessageBoxResult result = MessageBox.Show("Is it currently 2-5 PM?",
"Time", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
NavigationService.Navigate(new Uri("TacoBell.xaml", UriKind.Relative));
}
else if (result == MessageBoxResult.Cancel)
{
NavigationService.Navigate(new Uri("Pizza.xaml", UriKind.Relative));
}
}
}
}