Skip to content
Snippets Groups Projects
Commit dfec90e5 authored by Paul-Winpenny's avatar Paul-Winpenny
Browse files

Updated the format to use MVVM, which will help with long term development.

parent 0fb18d65
No related branches found
No related tags found
1 merge request!1App now has a basic structure and BLE support
File added
using System.Windows.Input;
using Microsoft.Maui.Controls;
namespace RobobinApp
{
public partial class MainPage : ContentPage
{
public ICommand ConnectToRobobinCommand { get; }
public MainPage()
{
InitializeComponent();
// Create the command and assign it to the handler method
ConnectToRobobinCommand = new Command(OnConnectToRobobin);
BindingContext = this; // Set the BindingContext to the current page
}
// Command handler method
private void OnConnectToRobobin()
{
// Logic to connect to Robobin goes here
DisplayAlert("Connection", "Connecting to Robobin...", "OK");
}
}
}
......@@ -5,9 +5,5 @@
<ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework>
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
</PropertyGroup>
<ItemGroup>
<MauiXaml Update="LeftBox.xaml">
<SubType>Designer</SubType>
</MauiXaml>
</ItemGroup>
<ItemGroup />
</Project>
\ No newline at end of file
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Microsoft.Maui.Controls;
namespace RobobinApp
{
public class MainPageViewModel : INotifyPropertyChanged
{
private bool _isBusy;
private string _statusMessage;
public ICommand ConnectToRobobinCommand { get; }
public MainPageViewModel()
{
ConnectToRobobinCommand = new Command(async () => await OnConnectToRobobin());
}
public bool IsBusy
{
get => _isBusy;
set
{
_isBusy = value;
OnPropertyChanged();
}
}
public string StatusMessage
{
get => _statusMessage;
set
{
_statusMessage = value;
OnPropertyChanged();
}
}
private async Task OnConnectToRobobin()
{
try
{
IsBusy = true;
StatusMessage = "Connecting to Robobin...";
StatusMessage = "Connected to Robobin!";
await Application.Current.MainPage.DisplayAlert("Connection", StatusMessage, "OK");
}
catch (Exception ex)
{
StatusMessage = $"Failed to connect: {ex.Message}";
await Application.Current.MainPage.DisplayAlert("Error", StatusMessage, "OK");
}
finally
{
IsBusy = false;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
File moved
<?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:local="clr-namespace:RobobinApp"
x:Class="RobobinApp.MainPage"
Title="">
<ContentPage.Resources>
<ResourceDictionary>
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.MenuBarItems>
<MenuBarItem Text="Admin">
<MenuFlyoutItem Text="Connect to Robobin" Command="{Binding ConnectToRobobinCommand}" />
</MenuBarItem>
</ContentPage.MenuBarItems>
<!-- Main grid that holds all elements -->
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<!-- Only one row filling the available height -->
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<!-- Left box -->
<ColumnDefinition Width="2*" />
<!-- Center box (bigger) -->
<ColumnDefinition Width="1*" />
<!-- Right box -->
</Grid.ColumnDefinitions>
<!-- Left side box -->
<?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:local="clr-namespace:RobobinApp"
x:Class="RobobinApp.MainPage"
Title="">
<ContentPage.Resources>
<ResourceDictionary>
<ResourceDictionary Source="../Resources/Styles/Styles.xaml" />
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.BindingContext>
<local:MainPageViewModel />
</ContentPage.BindingContext>
<ContentPage.MenuBarItems>
<MenuBarItem Text="Admin">
<MenuFlyoutItem Text="Connect to Robobin" Command="{Binding ConnectToRobobinCommand}" />
</MenuBarItem>
</ContentPage.MenuBarItems>
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<local:LeftBox Grid.Column="0" Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
<!-- Center (big) box -->
<Frame BackgroundColor="White" BorderColor="Black" CornerRadius="5"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Grid.Column="1" Grid.Row="0">
<Label Text="Center Box" HorizontalOptions="Center" VerticalOptions="Center"/>
</Frame>
<!-- Right side box -->
<Frame BackgroundColor="Lavender" BorderColor="Black" CornerRadius="5"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Grid.Column="2" Grid.Row="0">
<Label Text="Right Box" HorizontalOptions="Center" VerticalOptions="Center"/>
</Frame>
</Grid>
</ContentPage>
<Frame BackgroundColor="White" BorderColor="Black" CornerRadius="5"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Grid.Column="1" Grid.Row="0">
<Label Text="{Binding StatusMessage}" HorizontalOptions="Center" VerticalOptions="Center"/>
</Frame>
<Frame BackgroundColor="Lavender" BorderColor="Black" CornerRadius="5"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Grid.Column="2" Grid.Row="0">
<Label Text="Right Box" HorizontalOptions="Center" VerticalOptions="Center"/>
</Frame>
<ActivityIndicator IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}"
VerticalOptions="Center" HorizontalOptions="Center"/>
</Grid>
</ContentPage>
using Microsoft.Maui.Controls;
namespace RobobinApp
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
}
......@@ -91,3 +91,10 @@ For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
for the application, we are following MVVM
Model: Handles data and business logic (e.g., represents a Robobin object).
View: Displays the UI and interacts with the user (e.g., buttons, labels).
ViewModel: Connects the Model to the View, providing data and commands (e.g., logic to connect to Robobin and update the status).
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment