最終更新:2020-03-31 (火) 17:34:35 (1480d)  

XAML
Top / XAML

Extensible Application Markup Language

Microsoftによって開発された、アプリケーションソフトのユーザインターフェイスを記述するための言語仕様

WPFアプリケーションの雛形

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>

    </Grid>
</Window>

比較

XAML

<Button Background="Red">
No
</Button>

C♯

Button btn = new Button();
btn.Background = Brushes.Red;
btn.Content = "No";
 

XAML/Window

  • x:Class?
  • xmlns
  • xmlns:x
  • xmlns:d
  • xmlns:mc
  • xmlns:local
  • mc:Ignorable?="d"
    <Window x:Class="WpfApplication1.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:WpfApplication1"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
    
        </Grid>
    </Window>

書き方

普通のプロパティ

  • <Button Width="100" Height="100" Content="Hoge" />

プロパティ要素構文

  • <Button Width="100" Height="100">
        <Button.Content>Hoge</Button.Content>
    </Button>

マークアップ拡張

ContentProperty

  • Buttonクラスの場合、親クラスであるContentControlクラスに[ContentProperty("Content")]属性が付いているため、<Button.Content>要素を省略できる

添付プロパティ

依存関係プロパティ

シリアライズ

参考