Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

データ駆動型の表示

アプリ実行


ソースコード

App.xaml
<Application x:Class="WpfApplication6.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
</Application>
MainWindow.xaml
<Window x:Class="WpfApplication6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:c="clr-namespace:System;assembly=mscorlib"
        Title="MainWindow" Height="350" Width="525">
    <!-- データをまず記述し、 -->
    <ContentControl>
        <ContentControl.Content>
            <SolidColorBrush Color="Red" />
        </ContentControl.Content>
    </ContentControl>
    <Window.Resources>
        <!-- 後からそのデータの表示方法を定義する -->
        <DataTemplate DataType="{x:Type SolidColorBrush}">
            <Ellipse Fill="{Binding}" />
        </DataTemplate>
    </Window.Resources>
</Window>