dkfarver

I have a combobox with binding to a dataset table and that works ok. However, on startup, I would like to have no item selected. Could someone point be in the right direction. My combo code is:

<ComboBox Height="22" Margin="103,54,0" Name="cbxtasks" VerticalAlignment="Top"

ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" ItemTemplate="{StaticResource TasksTemplate}"

SelectionChanged="cbxtasks_selectionChange" SelectedValuePath="id" >

<DataTemplate x:Key="TasksTemplate">

<TextBlock Text="{Binding Path=taskN}" />

</DataTemplate>




Re: Windows Presentation Foundation (WPF) Question: ComboBox binding need initial selection null

JDPeckham

SelectedValue="{Binding YourBoundProperty}"

then make sure "YourBoundProperty" is null.






Re: Windows Presentation Foundation (WPF) Question: ComboBox binding need initial selection null

lee d

did you try selectedindex =-1 or selectedValue={x:Null}






Re: Windows Presentation Foundation (WPF) Question: ComboBox binding need initial selection null

dkfarver

Thanks for your reply. My binding was done in page load so it always selected the first item. I tried changing selectedItem and selectedValue but that didn't work. Your suggestion to make the binding null caused me to only bind the control when it got focus. That does work, but seems like a workaround. Seems like I should be able to bind the control and select nothing or null.






Re: Windows Presentation Foundation (WPF) Question: ComboBox binding need initial selection null

Josh Smith

You might be able to accomplish this by creating a value converter which returns null from Convert() the first time it is called. All subsequent calls to Convert() would just return the input value. Once you have the converter class, assign an instance of it to the Binding's Converter property so that it will be used.






Re: Windows Presentation Foundation (WPF) Question: ComboBox binding need initial selection null

Vladd

If you don't need your selection being synchronized with selections outside the ComboBox control you can try setting IsSynchronizedWithCurrentItem="False".

Vlad





Re: Windows Presentation Foundation (WPF) Question: ComboBox binding need initial selection null

dkfarver

Thanks, that works.