より良いエンジニアを目指して

1日1つ。良くなる!上手くなる!

WPFでRadioButtonの項目をComboBoxにする

WPFになると、コンポーネントを組み合わせて、少し凝ったコンポーネントを作ってみたくなるものです。

RadioButtonの項目にComboBoxにしたいなと思いました。

f:id:rimever:20190718211705p:plain

出来るかなーと思ったのですが、ComboboxでRadioButton.Contentタグで囲めばできます。

stackoverflow.com

<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>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <RadioButton Content="Big" Width="100"/>
            <RadioButton Content="Small" Width="100"/>
            <RadioButton>
                <RadioButton.Content>
                    <ComboBox  Width="100" Text="100" IsEditable="True"></ComboBox>
                </RadioButton.Content>
            </RadioButton>
        </StackPanel>
    </Grid>
</Window>