WPF ComboBox IsSynchronised Default Value
- by LnDCobra
I am trying to display a default value (or even NO value) when selected index is -1, or selecteditem is null. This normally works perfectly fine but when I enable IsSynchronizedWithCurrentItem and set it to True, the first value in my DataTable gets displayed. How can I have both IsSynchronizedWithCurrentItem ="True" and show no/default value when it is loaded.
My Combo Box XAML:
<GroupBox Name="ClientGroup" Header="Client" Margin="63,182,0,177" FontSize="14" HorizontalAlignment="Left" Width="298">
<ComboBox Name="Supplier" Grid.IsSharedSizeScope="True" ItemsSource="{Binding}" IsEditable="True" Text="Please Choose..." TextSearch.TextPath="CompanyName" IsSynchronizedWithCurrentItem="True" Height="23" VerticalAlignment="Top" Margin="0,6,6,0" FontSize="11" StaysOpenOnEdit="True">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0,5,0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="CompanyName" />
<ColumnDefinition Width="Auto" SharedSizeGroup="EIC" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding CompanyName}" Grid.Column="0" />
<TextBlock Text="{Binding EIC, StringFormat=' ({0})'}" Grid.Column="1" FontFamily="Courier New" FontWeight="Bold" FontSize="12" />
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</GroupBox>
My CS code behind:
ClientGroup.DataContext = (new CompanyDealsDataSetTableAdapters.CompanyTableAdapter()).GetData();
When I start my application it automatically selects the first row in my data table. It works as expected when I remove IsSynchronizedWithCurrentItem.
Any ideas?