| VBプログラマの為のWPF入門VBプログラマの為のWPF入門
			そろそろWPFをやっておこう。 XAMLを整形するには?
			XAMLを直接各WPFプログラムですが、書いていると、インデントを整えたくなります。 サンプル目次
 MSのサンプルページ検索で、なかなかヒットすることがない?のかと思うので、 本家と言うことでリンクをはっておきます。 ComboBox
	今回作ってみたのは、 
	<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="348" Width="456" WindowStartupLocation="CenterScreen" >
    <Grid Width="472"> 最初からグリッドになっている。よーするに、こいつが標準と言うわけらしい。
        <Grid.Resources>
            <!--TargetTypeを指定すると、個々の記述は不要-->
            <Style TargetType="ComboBox">
                <Setter Property="Margin" Value="40,10,0,0" />
            </Style>
            <!--名前月スタイルでコントロールのマージンを一括設定。しかし個々のコントロールに記述する必要あり。TargetTypeより優先される-->
            <Style x:Key="thisPG_Margin">
                <Setter Property="Control.Margin" Value="20,10,0,0" />
            </Style>
        </Grid.Resources>
        <Border BorderBrush="#FFC05C1A" BorderThickness="1" Height="Auto" HorizontalAlignment="Left" Margin="23,38,0,0" Name="Border1" VerticalAlignment="Top" Width="Auto" Background="#699D303A" CornerRadius="10">
            <Grid Height="249" Width="401">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Label Grid.Row="0" Content="Borderコントロール" Height="28" HorizontalAlignment="Left" Name="Label1" VerticalAlignment="Top" Style="{StaticResource thisPG_Margin}" />
                <Button Grid.Row="1" Content="都道府県取得" Height="39" HorizontalAlignment="Left" Name="Button1" VerticalAlignment="Top" Width="121" Style="{StaticResource thisPG_Margin}" />
                <CheckBox Content="CheckBox" Grid.Row="2" Height="16" HorizontalAlignment="Left" Name="CheckBox1" VerticalAlignment="Top" Style="{StaticResource thisPG_Margin}" />
                <Label Content="経過時間" Grid.Column="1" Grid.Row="2" Height="28" Name="Label2" />
                <ComboBox Grid.Row="3" Height="24" HorizontalAlignment="Left"  Name="ComboBox1" VerticalAlignment="Top" Width="120" Style="{StaticResource thisPG_Margin}" >
                    <ComboBoxItem Content="北海道" IsSelected="True" />
                    <ComboBoxItem Content="青森" />
                    <ComboBoxItem Content="秋田" />
                    <ComboBoxItem Content="岩手" />
                </ComboBox>
                <Image Grid.Row="4" Height="24" HorizontalAlignment="Left" Name="Image1" Stretch="Fill" VerticalAlignment="Top" Width="168" Style="{StaticResource thisPG_Margin}" Margin="20,10,0,0" />
                <ComboBox Grid.Row="3" Grid.Column="1" Height="24" HorizontalAlignment="Left" Name="ComboBox2" VerticalAlignment="Top" Width="120" Style="{StaticResource thisPG_Margin}" />
                <ComboBox Grid.Column="1" Grid.Row="4" Height="24" HorizontalAlignment="Left" Name="ComboBox3" VerticalAlignment="Top" Width="120" />
                <Button Content="都道府県検索2" Grid.Column="1" Grid.Row="1" Name="Button2" Width="155" Margin="23,10,23,9" />
            </Grid>
            
        </Border>
    </Grid>
	</Window>
	
	
	 
 で、これではいかにも芸が無いので、 VBで以前、ComboBoxに画像を追加した時のように、画像を入れてみたのが、次のサンプル。  方法は、XAMLで、 
	 <ComboBox Grid.Row="3" Height="24" HorizontalAlignment="Left"  Name="ComboBox1" VerticalAlignment="Top" Width="120" Style="{StaticResource thisPG_Margin}" >
                    <ComboBoxItem IsSelected="True">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Content="北海道" />
                            <Image Grid.Column="1" Name="Image2" Stretch="Fill" VerticalAlignment="Top" Source="/WpfApplicationTips;component/Images/o0640048011914843315.jpg" />
                        </Grid>
                    </ComboBoxItem>
                    <ComboBoxItem Content="青森" />
                    <ComboBoxItem Content="秋田" />
                    <ComboBoxItem Content="岩手" />
                </ComboBox>
	
	
	赤い箇所を書き換えただけ。 |