Skip to content

Instantly share code, notes, and snippets.

@hilapon
hilapon / AppShell.xaml
Created May 5, 2022 08:49
ShellContent を TabBar の配下に変更
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MauiApp5.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp5"
Shell.FlyoutBehavior="Disabled">
<TabBar>
<ShellContent Title="Hello, World!" ContentTemplate="{DataTemplate local:MainPage}" Route="MainPage" />
@hilapon
hilapon / AppShell.xaml
Created May 5, 2022 08:25
AppShell を編集
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MauiApp5.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp5"
Shell.FlyoutBehavior="Flyout">
<ShellContent Title="Hello, World!" ContentTemplate="{DataTemplate local:MainPage}" Route="MainPage" />
<ShellContent Title="Page1" ContentTemplate="{DataTemplate local:Page1}" Route="Page1" />
@hilapon
hilapon / Page1.xaml
Created May 5, 2022 06:02
ContentPage の変更
<?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"
x:Class="MauiApp5.Page1"
Title="Page1">
<StackLayout>
<Label Text="1" FontSize="72" VerticalOptions="Center" HorizontalOptions="Center" />
</StackLayout>
</ContentPage>
@hilapon
hilapon / AppShell.xaml
Created April 29, 2022 08:39
AppShell の初期状態
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MauiApp5.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp5"
Shell.FlyoutBehavior="Disabled">
<ShellContent
Title="Hello, World!"
@hilapon
hilapon / MainViewModel.cs
Created April 26, 2022 02:46
CommunityToolkit.Mvvm での ViewModel サンプル
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace MauiApp3 {
internal class MainViewModel : ObservableObject {
public RelayCommand IncrementCounterCommand { get; }
private int Counter;
public MainViewModel() {
@hilapon
hilapon / MainPage.xaml.cs
Last active April 25, 2022 07:21
コードビハインドは削除しておく
namespace MauiApp1;
public partial class MainPage : ContentPage {
public MainPage() {
InitializeComponent();
}
}
@hilapon
hilapon / MainPage.xaml
Last active April 25, 2022 06:22
ビューをビューモデルとバインドさせる
<?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:MauiApp1"
x:Class="MauiApp1.MainPage">
<ContentPage.BindingContext>
<local:MainViewModel />
</ContentPage.BindingContext>
<ScrollView>
<VerticalStackLayout Spacing="25" Padding="30">
@hilapon
hilapon / MainViewModel.cs
Last active April 25, 2022 07:39
ビューモデルにカウンタ更新用のコマンドを追加した
using System.ComponentModel;
using System.Windows.Input;
namespace MauiApp1 {
internal class MainViewModel : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
public ICommand CounterCommand { private set; get; }
private int Counter;
@hilapon
hilapon / MainViewModel.cs
Last active April 25, 2022 05:15
ビューモデルをプロジェクトに追加
using System.ComponentModel;
namespace MauiApp1 {
internal class MainViewModel : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
#region プロパティ
private string _CounterText;
public string CounterText {
@hilapon
hilapon / MainPage.xaml.cs
Created April 25, 2022 05:08
ボタンクリックイベントの実装
namespace MauiApp2;
public partial class MainPage : ContentPage {
int count = 0;
public MainPage() {
InitializeComponent();
}
private void OnCounterClicked(object sender, EventArgs e){