first commit
This commit is contained in:
commit
353dde03c5
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/.vs
|
||||||
|
/bin
|
||||||
|
/obj
|
32
App.xaml
Normal file
32
App.xaml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<Application xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="MobApp.App">
|
||||||
|
<!--
|
||||||
|
Define global resources and styles here, that apply to all pages in your app.
|
||||||
|
-->
|
||||||
|
<Application.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<Color x:Key="Primary">#2196F3</Color>
|
||||||
|
<Style TargetType="Button">
|
||||||
|
<Setter Property="TextColor" Value="White"></Setter>
|
||||||
|
<Setter Property="VisualStateManager.VisualStateGroups">
|
||||||
|
<VisualStateGroupList>
|
||||||
|
<VisualStateGroup x:Name="CommonStates">
|
||||||
|
<VisualState x:Name="Normal">
|
||||||
|
<VisualState.Setters>
|
||||||
|
<Setter Property="BackgroundColor" Value="{StaticResource Primary}" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
<VisualState x:Name="Disabled">
|
||||||
|
<VisualState.Setters>
|
||||||
|
<Setter Property="BackgroundColor" Value="#332196F3" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
</VisualStateGroup>
|
||||||
|
</VisualStateGroupList>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
32
App.xaml.cs
Normal file
32
App.xaml.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using MobApp.Services;
|
||||||
|
using MobApp.Views;
|
||||||
|
using System;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
|
namespace MobApp
|
||||||
|
{
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
|
||||||
|
public App()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
DependencyService.Register<MockDataStore>();
|
||||||
|
MainPage = new AppShell();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnStart()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnSleep()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnResume()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
136
AppShell.xaml
Normal file
136
AppShell.xaml
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
xmlns:local="clr-namespace:MobApp.Views"
|
||||||
|
Title="MobApp"
|
||||||
|
x:Class="MobApp.AppShell">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The overall app visual hierarchy is defined here, along with navigation.
|
||||||
|
|
||||||
|
https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Shell.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<Style x:Key="BaseStyle" TargetType="Element">
|
||||||
|
<Setter Property="Shell.BackgroundColor" Value="{StaticResource Primary}" />
|
||||||
|
<Setter Property="Shell.ForegroundColor" Value="White" />
|
||||||
|
<Setter Property="Shell.TitleColor" Value="White" />
|
||||||
|
<Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
|
||||||
|
<Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
|
||||||
|
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource Primary}" />
|
||||||
|
<Setter Property="Shell.TabBarForegroundColor" Value="White"/>
|
||||||
|
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
|
||||||
|
<Setter Property="Shell.TabBarTitleColor" Value="White"/>
|
||||||
|
</Style>
|
||||||
|
<Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
|
||||||
|
<Style TargetType="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Default Styles for all Flyout Items
|
||||||
|
https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#flyoutitem-and-menuitem-style-classes
|
||||||
|
-->
|
||||||
|
<Style Class="FlyoutItemLabelStyle" TargetType="Label">
|
||||||
|
<Setter Property="TextColor" Value="White"></Setter>
|
||||||
|
</Style>
|
||||||
|
<Style Class="FlyoutItemLayoutStyle" TargetType="Layout" ApplyToDerivedTypes="True">
|
||||||
|
<Setter Property="VisualStateManager.VisualStateGroups">
|
||||||
|
<VisualStateGroupList>
|
||||||
|
<VisualStateGroup x:Name="CommonStates">
|
||||||
|
<VisualState x:Name="Normal">
|
||||||
|
<VisualState.Setters>
|
||||||
|
<Setter Property="BackgroundColor" Value="{x:OnPlatform UWP=Transparent, iOS=White}" />
|
||||||
|
<Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="{StaticResource Primary}" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
<VisualState x:Name="Selected">
|
||||||
|
<VisualState.Setters>
|
||||||
|
<Setter Property="BackgroundColor" Value="{StaticResource Primary}" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
</VisualStateGroup>
|
||||||
|
</VisualStateGroupList>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Custom Style you can apply to any Flyout Item
|
||||||
|
-->
|
||||||
|
<Style Class="MenuItemLayoutStyle" TargetType="Layout" ApplyToDerivedTypes="True">
|
||||||
|
<Setter Property="VisualStateManager.VisualStateGroups">
|
||||||
|
<VisualStateGroupList>
|
||||||
|
<VisualStateGroup x:Name="CommonStates">
|
||||||
|
<VisualState x:Name="Normal">
|
||||||
|
<VisualState.Setters>
|
||||||
|
<Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="{StaticResource Primary}" />
|
||||||
|
</VisualState.Setters>
|
||||||
|
</VisualState>
|
||||||
|
</VisualStateGroup>
|
||||||
|
</VisualStateGroupList>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</Shell.Resources>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
When the Flyout is visible this defines the content to display in the flyout.
|
||||||
|
FlyoutDisplayOptions="AsMultipleItems" will create a separate flyout item for each child element
|
||||||
|
https://docs.microsoft.com/dotnet/api/xamarin.forms.shellgroupitem.flyoutdisplayoptions?view=xamarin-forms
|
||||||
|
-->
|
||||||
|
<FlyoutItem Title="About" Icon="icon_about.png">
|
||||||
|
<ShellContent Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
|
||||||
|
</FlyoutItem>
|
||||||
|
<FlyoutItem Title="Browse" Icon="icon_feed.png">
|
||||||
|
<ShellContent Route="ItemsPage" ContentTemplate="{DataTemplate local:ItemsPage}" />
|
||||||
|
</FlyoutItem>
|
||||||
|
|
||||||
|
<!-- When the Flyout is visible this will be a menu item you can tie a click behavior to -->
|
||||||
|
<MenuItem Text="Logout" StyleClass="MenuItemLayoutStyle" Clicked="OnMenuItemClicked">
|
||||||
|
</MenuItem>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
TabBar lets you define content that won't show up in a flyout menu. When this content is active
|
||||||
|
the flyout menu won't be available. This is useful for creating areas of the application where
|
||||||
|
you don't want users to be able to navigate away from. If you would like to navigate to this
|
||||||
|
content you can do so by calling
|
||||||
|
await Shell.Current.GoToAsync("//LoginPage");
|
||||||
|
-->
|
||||||
|
<TabBar>
|
||||||
|
<ShellContent Route="LoginPage" ContentTemplate="{DataTemplate local:LoginPage}" />
|
||||||
|
</TabBar>
|
||||||
|
|
||||||
|
<!-- Optional Templates
|
||||||
|
// These may be provided inline as below or as separate classes.
|
||||||
|
|
||||||
|
// This header appears at the top of the Flyout.
|
||||||
|
// https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#flyout-header
|
||||||
|
<Shell.FlyoutHeaderTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Grid>ContentHere</Grid>
|
||||||
|
</DataTemplate>
|
||||||
|
</Shell.FlyoutHeaderTemplate>
|
||||||
|
|
||||||
|
// ItemTemplate is for ShellItems as displayed in a Flyout
|
||||||
|
// https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#define-flyoutitem-appearance
|
||||||
|
<Shell.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<ContentView>
|
||||||
|
Bindable Properties: Title, Icon
|
||||||
|
</ContentView>
|
||||||
|
</DataTemplate>
|
||||||
|
</Shell.ItemTemplate>
|
||||||
|
|
||||||
|
// MenuItemTemplate is for MenuItems as displayed in a Flyout
|
||||||
|
// https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#define-menuitem-appearance
|
||||||
|
<Shell.MenuItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<ContentView>
|
||||||
|
Bindable Properties: Text, Icon
|
||||||
|
</ContentView>
|
||||||
|
</DataTemplate>
|
||||||
|
</Shell.MenuItemTemplate>
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
</Shell>
|
23
AppShell.xaml.cs
Normal file
23
AppShell.xaml.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using MobApp.ViewModels;
|
||||||
|
using MobApp.Views;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace MobApp
|
||||||
|
{
|
||||||
|
public partial class AppShell : Xamarin.Forms.Shell
|
||||||
|
{
|
||||||
|
public AppShell()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
Routing.RegisterRoute(nameof(ItemDetailPage), typeof(ItemDetailPage));
|
||||||
|
Routing.RegisterRoute(nameof(NewItemPage), typeof(NewItemPage));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnMenuItemClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await Shell.Current.GoToAsync("//LoginPage");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
AssemblyInfo.cs
Normal file
3
AssemblyInfo.cs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
|
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
|
34
GettingStarted.txt
Normal file
34
GettingStarted.txt
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
Welcome to Xamarin.Forms! Here are some tips to get started building your app.
|
||||||
|
|
||||||
|
Building Your App UI
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
XAML Hot Reload quickly applies UI changes as you make them to your running app.
|
||||||
|
This is the most productive way to preview and iteratively create your UI.
|
||||||
|
|
||||||
|
Try it out:
|
||||||
|
|
||||||
|
1. Run the app by clicking the Start Debugging (play) button in the above toolbar.
|
||||||
|
2. Open <MainProject>\Views\AboutPage.xaml.
|
||||||
|
Don't stop the app - keep it running while making changes.
|
||||||
|
3. Change something! Hint: change the Accent color on line 14 from "#96d1ff" to "Pink".
|
||||||
|
4. Watch the About screen update on the device or emulator, with the logo background now pink.
|
||||||
|
|
||||||
|
Keep going and try more changes!
|
||||||
|
|
||||||
|
QuickStart Guide
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Learn more of the fundamentals for building apps with Xamarin here: https://aka.ms/xamarin-quickstart
|
||||||
|
|
||||||
|
Your App Shell
|
||||||
|
--------------
|
||||||
|
|
||||||
|
This template uses Shell, an app container that reduces the complexity of your apps by providing fundamental features including:
|
||||||
|
|
||||||
|
- A single place to describe the app's visual hierarchy.
|
||||||
|
- Common navigation such as a flyout menu and tabs.
|
||||||
|
- A URI-based navigation scheme that permits navigation to any page in the application.
|
||||||
|
- An integrated search handler.
|
||||||
|
|
||||||
|
Open AppShell.xaml to begin exploring. To learn more about Shell visit: https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/introduction
|
13
MobApp.csproj
Normal file
13
MobApp.csproj
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
|
||||||
|
<ProduceReferenceAssemblyInOutDir>true</ProduceReferenceAssemblyInOutDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2196" />
|
||||||
|
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
11
Models/Item.cs
Normal file
11
Models/Item.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MobApp.Models
|
||||||
|
{
|
||||||
|
public class Item
|
||||||
|
{
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string Text { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
}
|
||||||
|
}
|
15
Services/IDataStore.cs
Normal file
15
Services/IDataStore.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MobApp.Services
|
||||||
|
{
|
||||||
|
public interface IDataStore<T>
|
||||||
|
{
|
||||||
|
Task<bool> AddItemAsync(T item);
|
||||||
|
Task<bool> UpdateItemAsync(T item);
|
||||||
|
Task<bool> DeleteItemAsync(string id);
|
||||||
|
Task<T> GetItemAsync(string id);
|
||||||
|
Task<IEnumerable<T>> GetItemsAsync(bool forceRefresh = false);
|
||||||
|
}
|
||||||
|
}
|
60
Services/MockDataStore.cs
Normal file
60
Services/MockDataStore.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using MobApp.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MobApp.Services
|
||||||
|
{
|
||||||
|
public class MockDataStore : IDataStore<Item>
|
||||||
|
{
|
||||||
|
readonly List<Item> items;
|
||||||
|
|
||||||
|
public MockDataStore()
|
||||||
|
{
|
||||||
|
items = new List<Item>()
|
||||||
|
{
|
||||||
|
new Item { Id = Guid.NewGuid().ToString(), Text = "First item", Description="This is an item description." },
|
||||||
|
new Item { Id = Guid.NewGuid().ToString(), Text = "Second item", Description="This is an item description." },
|
||||||
|
new Item { Id = Guid.NewGuid().ToString(), Text = "Third item", Description="This is an item description." },
|
||||||
|
new Item { Id = Guid.NewGuid().ToString(), Text = "Fourth item", Description="This is an item description." },
|
||||||
|
new Item { Id = Guid.NewGuid().ToString(), Text = "Fifth item", Description="This is an item description." },
|
||||||
|
new Item { Id = Guid.NewGuid().ToString(), Text = "Sixth item", Description="This is an item description." }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> AddItemAsync(Item item)
|
||||||
|
{
|
||||||
|
items.Add(item);
|
||||||
|
|
||||||
|
return await Task.FromResult(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> UpdateItemAsync(Item item)
|
||||||
|
{
|
||||||
|
var oldItem = items.Where((Item arg) => arg.Id == item.Id).FirstOrDefault();
|
||||||
|
items.Remove(oldItem);
|
||||||
|
items.Add(item);
|
||||||
|
|
||||||
|
return await Task.FromResult(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> DeleteItemAsync(string id)
|
||||||
|
{
|
||||||
|
var oldItem = items.Where((Item arg) => arg.Id == id).FirstOrDefault();
|
||||||
|
items.Remove(oldItem);
|
||||||
|
|
||||||
|
return await Task.FromResult(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Item> GetItemAsync(string id)
|
||||||
|
{
|
||||||
|
return await Task.FromResult(items.FirstOrDefault(s => s.Id == id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Item>> GetItemsAsync(bool forceRefresh = false)
|
||||||
|
{
|
||||||
|
return await Task.FromResult(items);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
ViewModels/AboutViewModel.cs
Normal file
18
ViewModels/AboutViewModel.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using Xamarin.Essentials;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace MobApp.ViewModels
|
||||||
|
{
|
||||||
|
public class AboutViewModel : BaseViewModel
|
||||||
|
{
|
||||||
|
public AboutViewModel()
|
||||||
|
{
|
||||||
|
Title = "About";
|
||||||
|
OpenWebCommand = new Command(async () => await Browser.OpenAsync("https://aka.ms/xamarin-quickstart"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICommand OpenWebCommand { get; }
|
||||||
|
}
|
||||||
|
}
|
54
ViewModels/BaseViewModel.cs
Normal file
54
ViewModels/BaseViewModel.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using MobApp.Models;
|
||||||
|
using MobApp.Services;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace MobApp.ViewModels
|
||||||
|
{
|
||||||
|
public class BaseViewModel : INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
public IDataStore<Item> DataStore => DependencyService.Get<IDataStore<Item>>();
|
||||||
|
|
||||||
|
bool isBusy = false;
|
||||||
|
public bool IsBusy
|
||||||
|
{
|
||||||
|
get { return isBusy; }
|
||||||
|
set { SetProperty(ref isBusy, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
string title = string.Empty;
|
||||||
|
public string Title
|
||||||
|
{
|
||||||
|
get { return title; }
|
||||||
|
set { SetProperty(ref title, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected bool SetProperty<T>(ref T backingStore, T value,
|
||||||
|
[CallerMemberName] string propertyName = "",
|
||||||
|
Action onChanged = null)
|
||||||
|
{
|
||||||
|
if (EqualityComparer<T>.Default.Equals(backingStore, value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
backingStore = value;
|
||||||
|
onChanged?.Invoke();
|
||||||
|
OnPropertyChanged(propertyName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region INotifyPropertyChanged
|
||||||
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
|
||||||
|
{
|
||||||
|
var changed = PropertyChanged;
|
||||||
|
if (changed == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
57
ViewModels/ItemDetailViewModel.cs
Normal file
57
ViewModels/ItemDetailViewModel.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
using MobApp.Models;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace MobApp.ViewModels
|
||||||
|
{
|
||||||
|
[QueryProperty(nameof(ItemId), nameof(ItemId))]
|
||||||
|
public class ItemDetailViewModel : BaseViewModel
|
||||||
|
{
|
||||||
|
private string itemId;
|
||||||
|
private string text;
|
||||||
|
private string description;
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get => text;
|
||||||
|
set => SetProperty(ref text, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Description
|
||||||
|
{
|
||||||
|
get => description;
|
||||||
|
set => SetProperty(ref description, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ItemId
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
itemId = value;
|
||||||
|
LoadItemId(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void LoadItemId(string itemId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var item = await DataStore.GetItemAsync(itemId);
|
||||||
|
Id = item.Id;
|
||||||
|
Text = item.Text;
|
||||||
|
Description = item.Description;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("Failed to Load Item");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
84
ViewModels/ItemsViewModel.cs
Normal file
84
ViewModels/ItemsViewModel.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
using MobApp.Models;
|
||||||
|
using MobApp.Views;
|
||||||
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace MobApp.ViewModels
|
||||||
|
{
|
||||||
|
public class ItemsViewModel : BaseViewModel
|
||||||
|
{
|
||||||
|
private Item _selectedItem;
|
||||||
|
|
||||||
|
public ObservableCollection<Item> Items { get; }
|
||||||
|
public Command LoadItemsCommand { get; }
|
||||||
|
public Command AddItemCommand { get; }
|
||||||
|
public Command<Item> ItemTapped { get; }
|
||||||
|
|
||||||
|
public ItemsViewModel()
|
||||||
|
{
|
||||||
|
Title = "Browse";
|
||||||
|
Items = new ObservableCollection<Item>();
|
||||||
|
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());
|
||||||
|
|
||||||
|
ItemTapped = new Command<Item>(OnItemSelected);
|
||||||
|
|
||||||
|
AddItemCommand = new Command(OnAddItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task ExecuteLoadItemsCommand()
|
||||||
|
{
|
||||||
|
IsBusy = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Items.Clear();
|
||||||
|
var items = await DataStore.GetItemsAsync(true);
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
Items.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsBusy = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnAppearing()
|
||||||
|
{
|
||||||
|
IsBusy = true;
|
||||||
|
SelectedItem = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Item SelectedItem
|
||||||
|
{
|
||||||
|
get => _selectedItem;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty(ref _selectedItem, value);
|
||||||
|
OnItemSelected(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnAddItem(object obj)
|
||||||
|
{
|
||||||
|
await Shell.Current.GoToAsync(nameof(NewItemPage));
|
||||||
|
}
|
||||||
|
|
||||||
|
async void OnItemSelected(Item item)
|
||||||
|
{
|
||||||
|
if (item == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// This will push the ItemDetailPage onto the navigation stack
|
||||||
|
await Shell.Current.GoToAsync($"{nameof(ItemDetailPage)}?{nameof(ItemDetailViewModel.ItemId)}={item.Id}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
ViewModels/LoginViewModel.cs
Normal file
24
ViewModels/LoginViewModel.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using MobApp.Views;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace MobApp.ViewModels
|
||||||
|
{
|
||||||
|
public class LoginViewModel : BaseViewModel
|
||||||
|
{
|
||||||
|
public Command LoginCommand { get; }
|
||||||
|
|
||||||
|
public LoginViewModel()
|
||||||
|
{
|
||||||
|
LoginCommand = new Command(OnLoginClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnLoginClicked(object obj)
|
||||||
|
{
|
||||||
|
// Prefixing with `//` switches to a different navigation stack instead of pushing to the active one
|
||||||
|
await Shell.Current.GoToAsync($"//{nameof(AboutPage)}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
65
ViewModels/NewItemViewModel.cs
Normal file
65
ViewModels/NewItemViewModel.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using MobApp.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace MobApp.ViewModels
|
||||||
|
{
|
||||||
|
public class NewItemViewModel : BaseViewModel
|
||||||
|
{
|
||||||
|
private string text;
|
||||||
|
private string description;
|
||||||
|
|
||||||
|
public NewItemViewModel()
|
||||||
|
{
|
||||||
|
SaveCommand = new Command(OnSave, ValidateSave);
|
||||||
|
CancelCommand = new Command(OnCancel);
|
||||||
|
this.PropertyChanged +=
|
||||||
|
(_, __) => SaveCommand.ChangeCanExecute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ValidateSave()
|
||||||
|
{
|
||||||
|
return !String.IsNullOrWhiteSpace(text)
|
||||||
|
&& !String.IsNullOrWhiteSpace(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get => text;
|
||||||
|
set => SetProperty(ref text, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Description
|
||||||
|
{
|
||||||
|
get => description;
|
||||||
|
set => SetProperty(ref description, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command SaveCommand { get; }
|
||||||
|
public Command CancelCommand { get; }
|
||||||
|
|
||||||
|
private async void OnCancel()
|
||||||
|
{
|
||||||
|
// This will pop the current page off the navigation stack
|
||||||
|
await Shell.Current.GoToAsync("..");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnSave()
|
||||||
|
{
|
||||||
|
Item newItem = new Item()
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid().ToString(),
|
||||||
|
Text = Text,
|
||||||
|
Description = Description
|
||||||
|
};
|
||||||
|
|
||||||
|
await DataStore.AddItemAsync(newItem);
|
||||||
|
|
||||||
|
// This will pop the current page off the navigation stack
|
||||||
|
await Shell.Current.GoToAsync("..");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
Views/AboutPage.xaml
Normal file
52
Views/AboutPage.xaml
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="MobApp.Views.AboutPage"
|
||||||
|
xmlns:vm="clr-namespace:MobApp.ViewModels"
|
||||||
|
Title="{Binding Title}">
|
||||||
|
|
||||||
|
<ContentPage.BindingContext>
|
||||||
|
<vm:AboutViewModel />
|
||||||
|
</ContentPage.BindingContext>
|
||||||
|
|
||||||
|
<ContentPage.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<Color x:Key="Accent">#96d1ff</Color>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</ContentPage.Resources>
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<StackLayout BackgroundColor="{StaticResource Accent}" VerticalOptions="FillAndExpand" HorizontalOptions="Fill">
|
||||||
|
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Center">
|
||||||
|
<ContentView Padding="0,40,0,40" VerticalOptions="FillAndExpand">
|
||||||
|
<Image Source="xamarin_logo.png" VerticalOptions="Center" HeightRequest="64" />
|
||||||
|
</ContentView>
|
||||||
|
</StackLayout>
|
||||||
|
</StackLayout>
|
||||||
|
<ScrollView Grid.Row="1">
|
||||||
|
<StackLayout Orientation="Vertical" Padding="30,24,30,24" Spacing="10">
|
||||||
|
<Label Text="Start developing now" FontSize="Title"/>
|
||||||
|
<Label Text="Make changes to your XAML file and save to see your UI update in the running app with XAML Hot Reload. Give it a try!" FontSize="16" Padding="0,0,0,0"/>
|
||||||
|
<Label FontSize="16" Padding="0,24,0,0">
|
||||||
|
<Label.FormattedText>
|
||||||
|
<FormattedString>
|
||||||
|
<FormattedString.Spans>
|
||||||
|
<Span Text="Learn more at "/>
|
||||||
|
<Span Text="https://aka.ms/xamarin-quickstart" FontAttributes="Bold"/>
|
||||||
|
</FormattedString.Spans>
|
||||||
|
</FormattedString>
|
||||||
|
</Label.FormattedText>
|
||||||
|
</Label>
|
||||||
|
<Button Margin="0,10,0,0" Text="Learn more"
|
||||||
|
Command="{Binding OpenWebCommand}"
|
||||||
|
BackgroundColor="{StaticResource Primary}"
|
||||||
|
TextColor="White" />
|
||||||
|
</StackLayout>
|
||||||
|
</ScrollView>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</ContentPage>
|
15
Views/AboutPage.xaml.cs
Normal file
15
Views/AboutPage.xaml.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
|
namespace MobApp.Views
|
||||||
|
{
|
||||||
|
public partial class AboutPage : ContentPage
|
||||||
|
{
|
||||||
|
public AboutPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Views/ItemDetailPage.xaml
Normal file
14
Views/ItemDetailPage.xaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="MobApp.Views.ItemDetailPage"
|
||||||
|
Title="{Binding Title}">
|
||||||
|
|
||||||
|
<StackLayout Spacing="20" Padding="15">
|
||||||
|
<Label Text="Text:" FontSize="Medium" />
|
||||||
|
<Label Text="{Binding Text}" FontSize="Small"/>
|
||||||
|
<Label Text="Description:" FontSize="Medium" />
|
||||||
|
<Label Text="{Binding Description}" FontSize="Small"/>
|
||||||
|
</StackLayout>
|
||||||
|
|
||||||
|
</ContentPage>
|
15
Views/ItemDetailPage.xaml.cs
Normal file
15
Views/ItemDetailPage.xaml.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using MobApp.ViewModels;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace MobApp.Views
|
||||||
|
{
|
||||||
|
public partial class ItemDetailPage : ContentPage
|
||||||
|
{
|
||||||
|
public ItemDetailPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
BindingContext = new ItemDetailViewModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
44
Views/ItemsPage.xaml
Normal file
44
Views/ItemsPage.xaml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="MobApp.Views.ItemsPage"
|
||||||
|
Title="{Binding Title}"
|
||||||
|
xmlns:local="clr-namespace:MobApp.ViewModels"
|
||||||
|
xmlns:model="clr-namespace:MobApp.Models"
|
||||||
|
x:Name="BrowseItemsPage">
|
||||||
|
|
||||||
|
<ContentPage.ToolbarItems>
|
||||||
|
<ToolbarItem Text="Add" Command="{Binding AddItemCommand}" />
|
||||||
|
</ContentPage.ToolbarItems>
|
||||||
|
<!--
|
||||||
|
x:DataType enables compiled bindings for better performance and compile time validation of binding expressions.
|
||||||
|
https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/data-binding/compiled-bindings
|
||||||
|
-->
|
||||||
|
<RefreshView x:DataType="local:ItemsViewModel" Command="{Binding LoadItemsCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">
|
||||||
|
<CollectionView x:Name="ItemsListView"
|
||||||
|
ItemsSource="{Binding Items}"
|
||||||
|
SelectionMode="None">
|
||||||
|
<CollectionView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<StackLayout Padding="10" x:DataType="model:Item">
|
||||||
|
<Label Text="{Binding Text}"
|
||||||
|
LineBreakMode="NoWrap"
|
||||||
|
Style="{DynamicResource ListItemTextStyle}"
|
||||||
|
FontSize="16" />
|
||||||
|
<Label Text="{Binding Description}"
|
||||||
|
LineBreakMode="NoWrap"
|
||||||
|
Style="{DynamicResource ListItemDetailTextStyle}"
|
||||||
|
FontSize="13" />
|
||||||
|
<StackLayout.GestureRecognizers>
|
||||||
|
<TapGestureRecognizer
|
||||||
|
NumberOfTapsRequired="1"
|
||||||
|
Command="{Binding Source={RelativeSource AncestorType={x:Type local:ItemsViewModel}}, Path=ItemTapped}"
|
||||||
|
CommandParameter="{Binding .}">
|
||||||
|
</TapGestureRecognizer>
|
||||||
|
</StackLayout.GestureRecognizers>
|
||||||
|
</StackLayout>
|
||||||
|
</DataTemplate>
|
||||||
|
</CollectionView.ItemTemplate>
|
||||||
|
</CollectionView>
|
||||||
|
</RefreshView>
|
||||||
|
</ContentPage>
|
32
Views/ItemsPage.xaml.cs
Normal file
32
Views/ItemsPage.xaml.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using MobApp.Models;
|
||||||
|
using MobApp.ViewModels;
|
||||||
|
using MobApp.Views;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
|
namespace MobApp.Views
|
||||||
|
{
|
||||||
|
public partial class ItemsPage : ContentPage
|
||||||
|
{
|
||||||
|
ItemsViewModel _viewModel;
|
||||||
|
|
||||||
|
public ItemsPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
BindingContext = _viewModel = new ItemsViewModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAppearing()
|
||||||
|
{
|
||||||
|
base.OnAppearing();
|
||||||
|
_viewModel.OnAppearing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Views/LoginPage.xaml
Normal file
14
Views/LoginPage.xaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
x:Class="MobApp.Views.LoginPage"
|
||||||
|
Shell.NavBarIsVisible="False">
|
||||||
|
<ContentPage.Content>
|
||||||
|
<StackLayout Padding="10,0,10,0" VerticalOptions="Center">
|
||||||
|
<Button VerticalOptions="Center" Text="Login" Command="{Binding LoginCommand}"/>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage.Content>
|
||||||
|
</ContentPage>
|
21
Views/LoginPage.xaml.cs
Normal file
21
Views/LoginPage.xaml.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using MobApp.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
|
namespace MobApp.Views
|
||||||
|
{
|
||||||
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||||
|
public partial class LoginPage : ContentPage
|
||||||
|
{
|
||||||
|
public LoginPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
this.BindingContext = new LoginViewModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
Views/NewItemPage.xaml
Normal file
22
Views/NewItemPage.xaml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="MobApp.Views.NewItemPage"
|
||||||
|
Shell.PresentationMode="ModalAnimated"
|
||||||
|
Title="New Item"
|
||||||
|
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
|
||||||
|
ios:Page.UseSafeArea="true">
|
||||||
|
<ContentPage.Content>
|
||||||
|
<StackLayout Spacing="3" Padding="15">
|
||||||
|
<Label Text="Text" FontSize="Medium" />
|
||||||
|
<Entry Text="{Binding Text, Mode=TwoWay}" FontSize="Medium" />
|
||||||
|
<Label Text="Description" FontSize="Medium" />
|
||||||
|
<Editor Text="{Binding Description, Mode=TwoWay}" AutoSize="TextChanges" FontSize="Medium" Margin="0" />
|
||||||
|
<StackLayout Orientation="Horizontal">
|
||||||
|
<Button Text="Cancel" Command="{Binding CancelCommand}" HorizontalOptions="FillAndExpand"></Button>
|
||||||
|
<Button Text="Save" Command="{Binding SaveCommand}" HorizontalOptions="FillAndExpand"></Button>
|
||||||
|
</StackLayout>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage.Content>
|
||||||
|
|
||||||
|
</ContentPage>
|
21
Views/NewItemPage.xaml.cs
Normal file
21
Views/NewItemPage.xaml.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using MobApp.Models;
|
||||||
|
using MobApp.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
|
namespace MobApp.Views
|
||||||
|
{
|
||||||
|
public partial class NewItemPage : ContentPage
|
||||||
|
{
|
||||||
|
public Item Item { get; set; }
|
||||||
|
|
||||||
|
public NewItemPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
BindingContext = new NewItemViewModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user