Skip to content

Commit

Permalink
Initialize state binding demo
Browse files Browse the repository at this point in the history
  • Loading branch information
SingletonSean committed Jun 29, 2024
1 parent 6fe412a commit f8d1c35
Show file tree
Hide file tree
Showing 38 changed files with 1,158 additions and 1 deletion.
10 changes: 9 additions & 1 deletion MauiTutorials.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComponentsOverStyles", "Com
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComplexBindings", "ComplexBindings\ComplexBindings.csproj", "{23D58DA4-DF6B-45FF-B428-662C45A41C25}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrudDemo", "CrudDemo\CrudDemo.csproj", "{3BF0982C-8A50-4912-8228-A49536A9A4AE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CrudDemo", "CrudDemo\CrudDemo.csproj", "{3BF0982C-8A50-4912-8228-A49536A9A4AE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StateBinding", "StateBinding\StateBinding.csproj", "{231F06C7-9BDE-41EC-8CB2-145995D195EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -113,6 +115,12 @@ Global
{3BF0982C-8A50-4912-8228-A49536A9A4AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BF0982C-8A50-4912-8228-A49536A9A4AE}.Release|Any CPU.Build.0 = Release|Any CPU
{3BF0982C-8A50-4912-8228-A49536A9A4AE}.Release|Any CPU.Deploy.0 = Release|Any CPU
{231F06C7-9BDE-41EC-8CB2-145995D195EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{231F06C7-9BDE-41EC-8CB2-145995D195EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{231F06C7-9BDE-41EC-8CB2-145995D195EA}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{231F06C7-9BDE-41EC-8CB2-145995D195EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{231F06C7-9BDE-41EC-8CB2-145995D195EA}.Release|Any CPU.Build.0 = Release|Any CPU
{231F06C7-9BDE-41EC-8CB2-145995D195EA}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
14 changes: 14 additions & 0 deletions StateBinding/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:StateBinding"
x:Class="StateBinding.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
12 changes: 12 additions & 0 deletions StateBinding/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace StateBinding
{
public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new AppShell();
}
}
}
13 changes: 13 additions & 0 deletions StateBinding/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="StateBinding.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:StateBinding.Pages"
Title="State Binding"
NavigationPage.HasNavigationBar="False"
Shell.FlyoutBehavior="Disabled">

<ShellContent ContentTemplate="{DataTemplate pages:MainView}" Route="MainPage" />

</Shell>
10 changes: 10 additions & 0 deletions StateBinding/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace StateBinding
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
25 changes: 25 additions & 0 deletions StateBinding/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Extensions.Logging;

namespace StateBinding
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
}
39 changes: 39 additions & 0 deletions StateBinding/Pages/MainView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="StateBinding.Pages.MainView"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<VerticalStackLayout Padding="50" MaximumWidthRequest="800">
<VerticalStackLayout>
<Label Text="First Name" />
<Entry Margin="0,2,0,0" Text="{Binding FirstName}" />
</VerticalStackLayout>

<VerticalStackLayout Margin="0,10,0,0">
<Label Text="Last Name" />
<Entry Margin="0,2,0,0" Text="{Binding LastName}" />
</VerticalStackLayout>

<VerticalStackLayout Margin="0,10,0,0">
<Label Text="Occupation" />
<Entry Margin="0,2,0,0" Text="{Binding Occupation}" />
</VerticalStackLayout>

<VerticalStackLayout Margin="0,10,0,0">
<Label Text="Favorite Color" />
<Entry Margin="0,2,0,0" Text="{Binding FavoriteColor}" />
</VerticalStackLayout>

<VerticalStackLayout Margin="0,10,0,0">
<Label Text="Favorite Food" />
<Entry Margin="0,2,0,0" Text="{Binding FavoriteFood}" />
</VerticalStackLayout>

<Button
Margin="0,20,0,0"
Command="{Binding SubmitCommand}"
Text="Submit" />

<Label Margin="0,20,0,0" Text="{Binding Output}" />
</VerticalStackLayout>
</ContentPage>
11 changes: 11 additions & 0 deletions StateBinding/Pages/MainView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace StateBinding.Pages;

public partial class MainView : ContentPage
{
public MainView()
{
InitializeComponent();

BindingContext = new MainViewModel();
}
}
105 changes: 105 additions & 0 deletions StateBinding/Pages/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using CommunityToolkit.Mvvm.Input;
using System.ComponentModel;

namespace StateBinding.Pages
{
public partial class MainViewModel : INotifyPropertyChanged
{
private string _firstName = string.Empty;
public string FirstName
{
get
{
return _firstName;
}
set
{
_firstName = value;
OnPropertyChanged(nameof(FirstName));
}
}

private string _lastName = string.Empty;
public string LastName
{
get
{
return _lastName;
}
set
{
_lastName = value;
OnPropertyChanged(nameof(LastName));
}
}

private string _occupation = string.Empty;
public string Occupation
{
get
{
return _occupation;
}
set
{
_occupation = value;
OnPropertyChanged(nameof(Occupation));
}
}

private string _favoriteColor = string.Empty;
public string FavoriteColor
{
get
{
return _favoriteColor;
}
set
{
_favoriteColor = value;
OnPropertyChanged(nameof(FavoriteColor));
}
}

private string _favoriteFood = string.Empty;
public string FavoriteFood
{
get
{
return _favoriteFood;
}
set
{
_favoriteFood = value;
OnPropertyChanged(nameof(FavoriteFood));
}
}

private string _output = string.Empty;
public string Output
{
get
{
return _output;
}
set
{
_output = value;
OnPropertyChanged(nameof(Output));
}
}

[RelayCommand]
private void Submit()
{
Output = $"{FirstName} {LastName} is a {Occupation} who likes {FavoriteFood} and the color {FavoriteColor}";
}

public event PropertyChangedEventHandler? PropertyChanged;

private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
6 changes: 6 additions & 0 deletions StateBinding/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
11 changes: 11 additions & 0 deletions StateBinding/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace StateBinding
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
}
16 changes: 16 additions & 0 deletions StateBinding/Platforms/Android/MainApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Android.App;
using Android.Runtime;

namespace StateBinding
{
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
6 changes: 6 additions & 0 deletions StateBinding/Platforms/Android/Resources/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
10 changes: 10 additions & 0 deletions StateBinding/Platforms/MacCatalyst/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Foundation;

namespace StateBinding
{
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
14 changes: 14 additions & 0 deletions StateBinding/Platforms/MacCatalyst/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- See https://aka.ms/maui-publish-app-store#add-entitlements for more information about adding entitlements.-->
<dict>
<!-- App Sandbox must be enabled to distribute a MacCatalyst app through the Mac App Store. -->
<key>com.apple.security.app-sandbox</key>
<true/>
<!-- When App Sandbox is enabled, this value is required to open outgoing network connections. -->
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

38 changes: 38 additions & 0 deletions StateBinding/Platforms/MacCatalyst/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- The Mac App Store requires you specify if the app uses encryption. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/itsappusesnonexemptencryption -->
<!-- <key>ITSAppUsesNonExemptEncryption</key> -->
<!-- Please indicate <true/> or <false/> here. -->

<!-- Specify the category for your app here. -->
<!-- Please consult https://developer.apple.com/documentation/bundleresources/information_property_list/lsapplicationcategorytype -->
<!-- <key>LSApplicationCategoryType</key> -->
<!-- <string>public.app-category.YOUR-CATEGORY-HERE</string> -->
<key>UIDeviceFamily</key>
<array>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>
16 changes: 16 additions & 0 deletions StateBinding/Platforms/MacCatalyst/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ObjCRuntime;
using UIKit;

namespace StateBinding
{
public class Program
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
}
Loading

0 comments on commit f8d1c35

Please sign in to comment.