views:

35

answers:

1

Hi

I'm trying to add some default text to combo boxes that will show when there is no item selected. I'm using a style to acheive this which works great when the combo is first loaded.

<Style TargetType="{x:Type igRibbon:ComboEditorTool}" x:Key="PleaseSelect">
<Style.Triggers>
<Trigger Property="SelectedIndex" Value="-1">
<Setter Property="Text" Value="Please Select" />
</Trigger>
</Style.Triggers>
</Style>

<igRibbon:ComboEditorTool Style="{StaticResource PleaseSelect}" 
ItemsSource="{Binding MyItems}" SelectedItem="{Binding MySelectedItem }" />

But when the combo's selected item is reset (by setting it to null, which sets the SelectedIndex to -1) it fails to display the default text (even though the the trigger does fire), what could be the reason for this? Is there a better way to reset the selected item?

Cheers

A: 

I'm not familiar with the Infragistics suite, but I suspect it's the same thing as with regular combo boxes: since you have a binding on SelectedItem, the Text cannot be set to an item that blatantly disobeys that binding; the Text IS a representation of the SelectedItem. If the SelectedItem is null, then the Text must also be a representation of null.

I'm guessing (didn't try it and I may be just plain wrong) you could probably accomplish this with an IValueConverter that returns a custom string when the passed object is null (and returns the object unchanged otherwise), set on the SelectedItem binding.

Alex Paven
Thanks for the answer. I've tried the following Converter but it doesn't work: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) return "Please Select"; else return value; }The combo doesn't display anything.
DarkIce