Home > DeveloperSection > Forums > Data Bound ComboBox partially unclickable
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    September-21-2013 7:06 AM

 WPF
Ratings:


 1 Reply(s)
 919  View(s)
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?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-21-2013 7:59 AM

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.


Don't want to miss updates? Please click the below button!

Follow MindStick