Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# (通用Windows App)System.NullReferenceException:对象引用未设置为对象的实例_C#_Xaml_Uwp - Fatal编程技术网

C# (通用Windows App)System.NullReferenceException:对象引用未设置为对象的实例

C# (通用Windows App)System.NullReferenceException:对象引用未设置为对象的实例,c#,xaml,uwp,C#,Xaml,Uwp,当我尝试运行非常简单的通用windows应用程序时,会弹出上面的异常。我试了好几次想把它修好,但它仍然在那里。我真的是编程新手,所以如果有人能帮助我,我会非常高兴。 这是我主页的设计: <UserControl x:Class="simpleCalc.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://sche

当我尝试运行非常简单的通用windows应用程序时,会弹出上面的异常。我试了好几次想把它修好,但它仍然在那里。我真的是编程新手,所以如果有人能帮助我,我会非常高兴。 这是我主页的设计:

<UserControl x:Class="simpleCalc.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Test_App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="#FFE2D7CC">
    <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="13,50,0,0" Text="Километри" 
TextWrapping="Wrap" VerticalAlignment="Top" Height="31" Width="114" FontFamily="Times New Roman" 
FontSize="22" FontWeight="Bold"
FontStyle="Italic"/>
    <TextBlock x:Name="textBlock1" HorizontalAlignment="Left" Margin="36,103,0,0" Text="Литри" 
TextWrapping="Wrap" VerticalAlignment="Top" Height="32" Width="114" FontFamily="Times New Roman" 
FontSize="22" FontWeight="Bold"
FontStyle="Italic"/>
    <TextBlock x:Name="textBlock2" HorizontalAlignment="Left" Margin="16,147,0,0" Text="Консумация" 
TextWrapping="Wrap" VerticalAlignment="Top" Height="31" Width="114" FontFamily="Times New Roman" 
FontSize="22" FontWeight="Bold"
FontStyle="Italic"/>
    <TextBox x:Name="mileage" HorizontalAlignment="Left" Height="28" Margin="149,47,0,0" 
TextWrapping="Wrap" Text="100" VerticalAlignment="Top" Width="120" Background="#FFD6F6F9"/>
    <TextBox x:Name="liters" HorizontalAlignment="Left" Height="31" Margin="149,97,0,0" 
TextWrapping="Wrap" Text="10" VerticalAlignment="Top" Width="120" Background="#FFD2EFF1"/>
    <TextBox x:Name="cons" HorizontalAlignment="Left" Height="27" Margin="149,145,0,0" 
TextWrapping="Wrap" Text="10" VerticalAlignment="Top" Width="120" Background="#FFC5EAEE"/>
    <TextBlock x:Name="textBlock3" HorizontalAlignment="Left"
Margin="274,147,0,0" TextWrapping="Wrap" Text="1/100 km" VerticalAlignment="Top"/>


    <Button x:Name="button1" Content="ИЗЧИСЛИ" HorizontalAlignment="Left"
Margin="149,199,0,0" VerticalAlignment="Top" Width="120" Click="Button_Click"
Height="35" Foreground="#FF3A2121" Background="#FFF32424">
        <Button.BorderBrush>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFA3AEB9" Offset="0"/>
                <GradientStop Color="#FF8399A9" Offset="0.375"/>
                <GradientStop Color="#FF718597" Offset="0.375"/>
                <GradientStop Color="#FFEE3760" Offset="1"/>
            </LinearGradientBrush>
        </Button.BorderBrush>
    </Button>
</Grid>

</UserControl>
} 当我运行应用程序(本例中为燃料的简单计算)时,它在此处抛出异常:

if (e.PrelaunchActivated == false)
        {
            if (rootFrame.Content == null)
            {
                ***rootFrame.Navigate(typeof(MainPage), e.Arguments);***
            }

我想这是因为你的主页是UserControl类型的。。尝试添加新的ContentPage而不是UserControl。

我认为这是因为您的主页属于UserControl类型。。尝试添加新的ContentPage而不是UserControl。
if (e.PrelaunchActivated == false)
        {
            if (rootFrame.Content == null)
            {
                ***rootFrame.Navigate(typeof(MainPage), e.Arguments);***
            }