WPF ComboBox IsSynchronized Default Value

I am trying to show the default value (or even the value NO) when the selected index is -1, or selecteditem is null. This works fine fine, but when I turn on IsSynchronizedWithCurrentItem and set it to True, the first value in my DataTable is displayed. How can I use IsSynchronizedWithCurrentItem = "True" and show the default value / value at boot time.

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 is behind:

ClientGroup.DataContext = (new CompanyDealsDataSetTableAdapters.CompanyTableAdapter()).GetData();

When I run the application, it automatically selects the first row in my data table. It works as expected when I remove IsSynchronizedWithCurrentItem.

Anyone have any solutions?

+3
1

, , .

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        Supplier.Text = null;
    }

, , null/default:).

+1

Source: https://habr.com/ru/post/1736468/


All Articles