rksoftware

Visual Studio とか C# とかが好きです

Uno Platform は今

Uno Platform、覚えていますか?
2018 年に OSS になり、日本では 2019 年 ~ 2020 年頃に話題になった複数プラットフォーム向けアプリを作る製品です。

特徴は C# + XAML で作れるところです。話題になった大きなポイントは 2 点。

  1. WebAssembly が作れる
  2. XAML が UWP の XAML

です。 1. は .NET 技術としては Blazor と競合しますが、Blazor WebAssembly の GA が 2022 年 05 月だったようで、その隙をついた形です。現在は Blazor WebAssemby の注目度が非常に高くなり、結果 Uno Platform の存在感がなくなってしまった感じかなとも思います。

1. 2. 合わせて簡単な表にしてみます。これは代表的なもので、例えば C# ではなく F# を使ったり、コミュニティで開発されている製品を使えば × が ○ になるものもあったりすると思います。(未調査)

MAUI Blazor Blazor (Hybrid) Uno Platform
言語 C# C# C# C#
UI 定義 XAML HTML + CSS HTML + CSS XAML
Web × ×
WebAssembly ×
Android ×
iOS ×
Windows (UWP) ×
Windows (WPF or WinForms) × ×
macOS ×
Linux × × ×

概要はこれくらいに、Uno Platform どうなってるの? というところを見てみましょう。

OSS となっているので GitHub にリポジトリがあります。
github.com

活発に開発されています。Pull requests も頻繁にクローズされていますね。

github.com

UI コントロール

以前に話題になった際には、UWP の XAML が使えることが話題でした。具体的に言うと、Xamarin.Forms と UWP では XAML という書式は同じでも、実装されているコントロールが異なるため、コントロール名やプロパティの多くが異なっていました。

※ 異なっていることの是非はここでは語りませんが ( 私は異なっていてヨシ! 派です )、UWP そのままで XAML で UI が作れることが注当時目された理由の一つだったことは間違いありません。

そんな UI コントロールですが今はどうなっているでしょう?

WinUI プロジェクト

まずは Visual Studio で WinUI プロジェクトのソリューションを作って UI の .xaml.cs を見てみましょう。

※ これを見てみましょうということで既に答えを言っているようなものですが。

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace App1
{
    /// <summary>
    /// An empty window that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
        }

        private void myButton_Click(object sender, RoutedEventArgs e)
        {
            myButton.Content = "Clicked";
        }
    }
}

次に Uno Platform のソリューションの UI の xaml.cs です。

using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace App1
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
    }
}

お判りいただけたでしょうか? どちらも Microsoft.UI.Xaml 名前空間が using されています。

UWP の場合は次のようです。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// 空白ページの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x411 を参照してください

namespace App1
{
    /// <summary>
    /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
    }
}

つまり、Uno Platform は WinUI になっています。

参考

docs.microsoft.com 引用

XAML/UI コードをコピーします。 多くの場合、単に名前空間を変更できます (たとえば、Windows.UI. から Microsoft.UI.)。

つまり、Microsoft.UI.*usng されているので WinUI です。

結論

Uno Platform は元気です。もし、MAUI か Blazor Hybrid かと迷うことがあったら選択肢に Uno Platform も加えて迷ってみてください。