2010-03-11 107 views
3

我試圖顯示一個默認值(甚至NO值)當選定的索引是-1,或selecteditem爲空。這通常工作得很好,但是當我啓用IsSynchronizedWithCurrentItem並將其設置爲True時,我的DataTable中的第一個值會顯示出來。我怎樣才能同時加載IsSynchronizedWithCurrentItem =「True」和不顯示/默認值。WPF組合框IsSynchronised默認值

我的組合框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> 

我的CS後面的代碼:

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

當我開始我的應用程序,它會自動選擇在我的數據表的第一行。它在我刪除IsSynchronizedWithCurrentItem時按預期工作。

任何人有任何解決方案?

回答

1

找到了答案,它比我想象的要簡單得多。

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

這似乎工作,我所有的綁定字段都設置爲空/默認值:)。