Когда я пытаюсь запустить очень простое универсальное приложение для 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>
А вот функциональный код:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace simpleCalc
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
double dMileage = Double.Parse(mileage.Text);
double dLiters = Double.Parse(liters.Text);
double dRes = 100 * (dLiters/dMileage);
cons.Text = dRes.ToString("##.##");
}
}
} Когда я запускаю приложение (в данном случае это простой расчет топлива), оно выдает исключение:
if (e.PrelaunchActivated == false)
{
if (rootFrame.Content == null)
{
***rootFrame.Navigate(typeof(MainPage), e.Arguments);***
}
Я думаю, это потому, что ваша MainPage имеет тип UserControl. Попробуйте добавить новую ContentPage вместо UserControl.
Я думаю, это потому, что ваша MainPage имеет тип UserControl. Попробуйте добавить новую ContentPage вместо UserControl.