Q099. コンボボックスの項目に整数リテラル値を設定するには?

A.ComboBoxItem を使わなくても、直接数値を設定することができます。

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Title="MainWindow" Height="130" Width="250">
    <Grid>
        <ComboBox Height="30" Width="120"
                  HorizontalContentAlignment="Right"
                  VerticalContentAlignment="Center"
                  SelectedIndex="0" >
            <sys:Int32>1</sys:Int32>
            <sys:Int32>2</sys:Int32>
            <sys:Int32>3</sys:Int32>
            <sys:Int32>4</sys:Int32>
            <sys:Int32>5</sys:Int32>
        </ComboBox>
    </Grid>
</Window>


WPF FAQ の目次に戻る