DATA BOUND COMBOBOX PARTIALLY UNCLICKABLE

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
WPF
 1262  View(s)
Ratings:
Rate this:

I have some ComboBoxes set up like this:

    <ComboBox Name="CB_OS" Grid.Row="5" ItemsSource="{Binding OS_Sellection}" SelectedIndex="0" Margin="2" SelectionChanged="OSSelectionChanged">

        <ComboBox.ItemTemplate>

            <DataTemplate>

                <ComboBoxItem Content="{Binding Name}" IsSelected="{Binding IsSelected, Mode=TwoWay}"/>

            </DataTemplate>

        </ComboBox.ItemTemplate>

    </ComboBox>

The ComboBox fills with ComboBoxItems correctly, but clicking on the text (Content) does not select the Item. I must click elsewhere, where there is no text to actually change the selected item.

If I change it to this:

<ComboBox Name="CB_OS" Grid.Row="5" SelectedIndex="0" Margin="2" SelectionChanged="OSSelectionChanged">

            <ComboBoxItem Content="OOOOOOOOO"/>

            <ComboBoxItem Content="OOOOOOOOO"/>

            <ComboBoxItem Content="OOOOOOOOO"/>

</ComboBox>

it works fine.

OS_Selection contains only the following members:

private string name;

private bool isChecked;

private bool isSelected;

So my question is: How can I make the entire row (item) clickable?

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Data Bound ComboBox partially unclickable

    Hi Ankita,


    Don't put a ComboBoxItem inside the ComboBox.ItemTemplate

    Change this:

         <ComboBox Name="CB_OS" Grid.Row="5" ItemsSource="{Binding OS_Sellection}" SelectedIndex="0" Margin="2" SelectionChanged="OSSelectionChanged">

            <ComboBox.ItemTemplate>

                <DataTemplate>

                    <ComboBoxItem Content="{Binding Name}" IsSelected="{Binding IsSelected, Mode=TwoWay}"/>

                </DataTemplate>

            </ComboBox.ItemTemplate>

        </ComboBox>

    for this:

    <ComboBox Grid.Row="5" Margin="2"

              ItemsSource="{Binding OS_Sellection}"

              DisplayMemberPath="Name"/>

    Also, WPF does not bind to private fields, only public properties.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!