0

I have a ComboBox with the values 1..21

When I drop down the comboBox, number 1 (item 0) is enabled, but all the other items are grayed out, and I can't select any of them. In fact, I can only see their values when scrolling through the list - otherwise they are completely transparent.

Here is my winrt-xmal:

            <ComboBox x:Name="cmbxInitialMapZoomSetting" Grid.Row="1" Grid.Column="1" Height="32" Margin="4" Width="120" HorizontalAlignment="Left" SelectionChanged="CmbxInitialMapZoomSetting_OnSelectionChanged">
                <Button Content="1"/>
                <Button Content="2"/>
                <Button Content="3"/>
        . . .
                <Button Content="19"/>
                <Button Content="20"/>
                <Button Content="21"/>
            </ComboBox>

...and here is the related code:

private void CmbxInitialMapZoomSetting_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    ApplicationData.Current.LocalSettings.Values["MapZoomSetting"] = cmbxInitialMapZoomSetting.SelectedValue;
}
1
  • It's a 'clash' of the default styles for the combo box and the button under the "Dark" theme. Bottom line, you'll need to create a style with appropriate foreground/background colors for the button and/or the ComboBox that works for you.
    – Jim O'Neil
    Nov 24, 2012 at 3:29

1 Answer 1

1

Is there a reason you are putting Buttons in ComboBox? You could use ComboBoxItems instead:

<ComboBox x:Name="cmbxInitialMapZoomSetting" Height="32" Margin="4" Width="120" HorizontalAlignment="Left" SelectionChanged="CmbxInitialMapZoomSetting_OnSelectionChanged">
    <ComboBoxItem>1</ComboBoxItem>
    <ComboBoxItem>2</ComboBoxItem>
    <ComboBoxItem>3</ComboBoxItem>
    <ComboBoxItem>4</ComboBoxItem>
    <ComboBoxItem>5</ComboBoxItem>
</ComboBox>

You only need a minor modification of your event handler to make this work:

private void CmbxInitialMapZoomSetting_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    ApplicationData.Current.LocalSettings.Values["MapZoomSetting"] = (cmbxInitialMapZoomSetting.SelectedValue as ComboBoxItem).Content.ToString();
}
3
  • I didn't declare the items as buttons; they are declared that way automatically when you add items via the Properties pane. Nov 24, 2012 at 20:26
  • Perfect - that works like the proverbial cha[mp,rm], except that at design-time the comboBox is now shown expanded/dropped down. Nov 24, 2012 at 20:36
  • @ClayShannon For me its expanded at design time only when in XAML view the focus is on ComboBox or one of its items. Its collapsed otherwise.
    – Damir Arh
    Nov 25, 2012 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.