0

I have seen a lot of topic about creating a ComboBox using TreeView but not with an Editable one (the topics shows things with no use of ComboBoxes).

I am currently using the ComboBox with a Grid Panel.

Here is the XAML I am currently using :

    <Window x:Class="DandDAdventures.XAML.AddPJWindow"
        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:DandDAdventures.XAML"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="Example" Height="300" Width="300">
    <DockPanel>
        <Grid VerticalAlignment="Top">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>

            <ComboBox  Grid.Column="1" Grid.Row="2" IsEditable="True" x:Name="RaceCB">
                <ComboBoxItem HorizontalAlignment="Stretch">
                    <TreeView ItemsSource="{Binding Children}" x:Name="RaceTV" SelectedItemChanged="RaceTVSelectedItemChanged" >
                        <TreeViewItem Header="Hello">
                            <TreeViewItem Header="HelloLvl2"/>
                        </TreeViewItem>
                    </TreeView>
                </ComboBoxItem>

                <ComboBox.Text>
                    <Binding Path="SelectedItem.Header" ElementName="RaceTV" Mode="OneWay"/>
                </ComboBox.Text>
            </ComboBox>
        </Grid>
    </DockPanel>
</Window>

When I have selected an Item, the ComboBox shows "System.Windows.Controls.ComboBoxItem"

I don't know what to do and I need the ComboBox to be editabled.

Thank you a lot !

Gaulois94
  • 159
  • 9
  • 1
    What do you *want* it to show when there is a selected item? Right now the selected item *is* the `ComboBoxItem`, because you literally added one manually, and placed the `TreeView` inside it. Are you *sure* this is what you want? Because it seems like a very strange setup to me. Are you trying to get the options for the ComboBox popup to display as a tree? If so, this isn't the way to do it. The correct way is fairly involved, but this should help you: https://stackoverflow.com/questions/722700/wpf-treeview-inside-a-combobox – Bradley Uffner Aug 18 '17 at 00:08
  • I have already seen this, and got some problems about the fact that the TextBox is unstylized is problematic to me... I want to print only the Header of the TreeViewItem selected, no more. I tried then in C# to manually set the property "Text" of the ComboBox – Gaulois94 Aug 18 '17 at 10:57

0 Answers0