0

I want to have a control similar to this? Is there a way to do this using WPF.

Sample Image:

Sample Image here

It is like a combobox but its comboboxitems works as menuitems. The menu item selected would be displayed in the combobox.

Dyy
  • 51
  • 7
  • You should first try some code before posting a question to help you. May be this will get you started https://zamjad.wordpress.com/2010/05/25/display-tree-view-inside-combo-box/. Post your code if it does not work. – Shivani Katukota May 22 '18 at 08:20
  • A couple of years ago, we had a requirement like this. I restyled MenuItem to look and behave like a branching combobox. It involved a fair amount of effort. – 15ee8f99-57ff-4f92-890c-b56153 May 22 '18 at 13:49

2 Answers2

0

If you need menu item then use menu item. I think it would be much harder to customize combobox.

El Barrent
  • 165
  • 5
0

I can confirm that there is no direct way to do this. The only workaround is to set up a Menu (with one big MenuItem) to make it look like a ComboBox. Here is the code before any DataBindings:

<Menu HorizontalAlignment="Left">
<MenuItem>
<MenuItem.Header>
    <Grid>
       <Grid.ColumnDefinitions>
          <ColumnDefinition Width="140"/>
          <ColumnDefinition Width="Auto"/>
       </Grid.ColumnDefinitions>
    <Label Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Stretch" Content="Select"/>
    <Border Grid.Column="1" HorizontalAlignment="Right">
        <ToggleButton IsChecked="False" IsHitTestVisible="False"
                BorderBrush="{TemplateBinding Border.BorderBrush}"
                Background="{TemplateBinding Panel.Background}">
        <ToggleButton.Style>
            <Style TargetType="ToggleButton">
            <Setter Property="OverridesDefaultStyle" Value="True" />
            <Setter Property="Focusable" Value="False" />
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="Control.Template">
                <Setter.Value>
                <ControlTemplate TargetType="ToggleButton">
                    <Path Data="M0,0L3.5,4 7,0z" Fill="#FF000000" Name="Arrow"
                                Margin="3,1,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </ControlTemplate>
                </Setter.Value>
            </Setter>
            </Style>
        </ToggleButton.Style>
        </ToggleButton>
    </Border>
    </Grid>
</MenuItem.Header>
<MenuItem Header="_Name">
    <MenuItem Header="_Last" />
    <MenuItem Header="_First" />
</MenuItem>
</MenuItem>