App doesnt run on Samsung S22 when not connected to computer
I am new to Maui programming. I found that when my phone is connected to the computer and I run Debug the app runs fine, however when I disconnect my phone and try to run the app by tapping the icon on my phone the app crashes right away.
My environment is Windows 10. VS 2022 Version 17.5.0 Preview 1.0.
namespace GasPrice_Maui;
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new Views.StartPage());
}
}
using GasPrice_Maui.Helpsers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace GasPrice_Maui.ViewModels
{
public partial class ViewModelStartPage : INotifyPropertyChanged
{
public ICommand Calculate => new Command(() => Calc());
string pricePerGallone;
public string PricePerGallone
{
get { return pricePerGallone; }
set { pricePerGallone = value; OnPropertyChanged(nameof(PricePerGallone)); }
}
string pricePerLiter = "CN$"; // pricePerGallone;
public string PricePerLiter
{
get { return pricePerLiter; }
set { pricePerLiter = value; OnPropertyChanged("PricePerLiter");}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
public void Calc()
{
CalculateGasPrice calc = new CalculateGasPrice();
string result = calc.Calculate(PricePerGallone);
PricePerLiter = result;
}
}
}
using CommunityToolkit.Maui;
namespace GasPrice_Maui;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
return builder.Build();
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="clr-namespace:CommunityToolkit.Maui.Behaviors;assembly=CommunityToolkit.Maui"
NavigationPage.HasNavigationBar="False"
xmlns:viewmodel="clr-namespace:GasPrice_Maui.ViewModels"
x:DataType="viewmodel:ViewModelStartPage"
x:Class="GasPrice_Maui.Views.StartPage">
<ContentPage.Behaviors>
<mct:StatusBarBehavior StatusBarColor="Gray"></mct:StatusBarBehavior>
</ContentPage.Behaviors>
<StackLayout>
<Frame BackgroundColor= "Gray" Padding="18" CornerRadius="0">
<Label Text="Gas Price Converter" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</Frame>
<Grid Margin="40,0,40,0">
<Grid.RowDefinitions>
<RowDefinition Height="240"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
</Grid.RowDefinitions>
<Image Source="gaspump" Margin="30,0,0,0" Grid.ColumnSpan="2" Grid.Row="0" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="120" WidthRequest="120"></Image>
<Label Grid.Row="1" Grid.Column="1" Text="Price per US Gallone" HorizontalTextAlignment="Center" FontSize="Large"></Label>
<Entry Grid.Row="2" Grid.Column="1" Placeholder="$0.00" Keyboard="Numeric" HorizontalTextAlignment="Center" Text="{Binding PricePerGallone}" FontSize="18"></Entry>
<Label Grid.Row="4" Grid.Column="1" Text="Price per Liter" HorizontalTextAlignment="Center" FontSize="Large"></Label>
<Label Grid.Row="5" Grid.Column="1" Text="{Binding PricePerLiter}" HorizontalTextAlignment="Center" FontSize="36" FontAttributes="Bold" TextColor="Black"></Label>
<Button Grid.Row="7" Grid.Column="1" WidthRequest="150" HorizontalOptions="Center" FontAttributes="Bold" FontSize="24" HeightRequest="50" Text="Calculate" Command="{Binding Calculate}"></Button>
<Label Grid.Row="8" Grid.Column="1" FontSize="Small" Text="Please allow for a +- 3% margin of error" VerticalTextAlignment="End" HorizontalTextAlignment="Center"></Label>
</Grid>
</StackLayout>
</ContentPage>