rksoftware

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

Uno Platform ふたつの空白のページ

Uno Platform で遊んでいたらフシギなことに気が付きました。

■ 不思議画像

f:id:rksoftware:20200225195244j:plain

何が不思議か? 項目を上から見てみましょう!

  • 一つ目は、「 空白のページ 」。二つ目は、「 空白のページ 」。

逆にしてみましょう。

  • 二つ目は、「 空白のページ 」。一つ目は、「 空白のページ 」。

縦に並べてみます。

  • 一つ目は、「 空白のページ 」。
  • 二つ目は、「 空白のページ 」。

完全に一致 しています。

■ 違い

このふたつ、何が違うのでしょう。
生まれるファイルはどちらを選んでもそれぞれふたつ .xaml と .xaml.cs です。

上の 「空白のページ

<Page
    x:Class="UnoApp2.Shared.BlankPage1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:UnoApp2.Shared"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>

    </Grid>
</Page>
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;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

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

下の 「空白のページ

<Page
    x:Class="UnoApp2.Shared.BlankPage1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:UnoApp2.Shared"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>

    </Grid>
</Page>
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=234238 を参照してください

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

■ コードは変わらない

コメントが英語か日本語かが違うだけで一致しています。コードは変わっていません。では何が変わっているのでしょう?
コードから目を話してソリューションエクスプローラーを見てみましょう。

上の 「空白のページ

下の 「空白のページ

ファイルがまとまっていたりいなかったりしています。

■ <プロジェクト名>.Shared.projitems

上下の 「 空白のページ 」 で <プロジェクト名>.Shared.projitems が僅かに変わっていました。
Visual Studio のソリューションエクスプローラーからは見えないので、Windows のエクスプローラーで確認するのがオススメです。

上の 「空白のページ

※ 一部抜粋

    <Compile Include="$(MSBuildThisFileDirectory)BlankPage1.xaml.cs">
      <DependentUpon>$fileinputname$.xaml</DependentUpon>
    </Compile>

下の 「空白のページ

※ 一部抜粋

    <Compile Include="$(MSBuildThisFileDirectory)BlankPage1.xaml.cs">
      <DependentUpon>BlankPage1.xaml</DependentUpon>
    </Compile>

■ まとめ

上の「 空白のページ 」の $fileinputname$.xamlBlankPage1.xaml に書き換えたら

ソリューションエクスプローラー上の見た目が、下の「 空白のページ 」と同じになりました。