もしも、WPF が xaml 形式ではなく yaml 形式で書く仕組みだったら
WPF とか UWP とか xaml 系について、頭の中で、ピコーン!ってなったので書いておきます。xaml って機能で見るとそんなに多くなくても、記述量で見ると長いんですよね。んで、意味はそのまま保持しながら、情報量だけ削減できればいいのにと思ったときに、それ、yaml で書き直せるヤムルー!ってなったので書いてみました。
目次
Xaml 形式(従来)
<Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp1" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid Margin="50"> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <TextBox x:Name="textbox1" /> <Button Grid.Row="1" x:Name="button1" Content="button1" Click="Button1_Click" /> </Grid> </Window>
Yaml 形式
Window: x:Class : WpfApp1.MainWindow xmlns : http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x : http://schemas.microsoft.com/winfx/2006/xaml xmlns:d : http://schemas.microsoft.com/expression/blend/2008 xmlns:mc : http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:local : clr-namespace:WpfApp1 mc:Ignorable : d Title : "Main Window" Height : 450 Width : 800 Grid: Margin : 50 Grid.RowDefinitions: - RowDefinition - RowDefinition TextBox: x:Name : textbox1 Button: Grid.Row : 1 x:Name : button1 Content : button1 Click : Button1_Click
yaml 見慣れてるけど書いたことなかったから、これであってるのかな?という心配が。なんだか Python みたいな見た目になりました。ブロックというかスコープがわかりづらいかな?慣れるまでの問題かも。あとは IDE 側で範囲の縦線が表示されれば、分かりやすくなるかもですね。というか json 形式なら分かりやすいかな?
メリット
- シンプルで見やすくなった
- 開始タグ・終了タグが無いため、余計な文字が無い。それにより、必要最低限の文字だけに集中できる
デメリット
- 開始タグ・終了タグが無いため、記述したコントロールの範囲がわかりづらい
- コロン(:)の区切り判定が難しいかも
終わりに
html や xml 形式のものなら、ツリー構造なので他にも書き直せそうですね。