2012-04-23 15 views
2

グリッド内にオブジェクトのリストといくつかのフィールドがあります。リスト(lvInvoices)内のオブジェクトが選択された場合、Iはグリッド(lyDetailForm)ののdataBindingを更新:コンボボックスに初期のオブジェクト値が反映されない

private void lvInvoices_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    int index = lvInvoices.SelectedIndex; 
    if (index != -1) 
    { 
    Invoice selectedInvoice = this.ListItems.ElementAt(index); 
    lyDetailForm.DataContext = selectedInvoice; 
    ((PdfViewer)this.pdfControlHost.Child).File = selectedInvoice.SourceFile.FullName; 
    } 
} 

lyDetailFormsで、私はいくつかのコントロールを持っています。グリッドのDataContextを設定すると、テキストコントロールが正しく更新されます。しかし、コンボボックスは一度設定するまで白く見えます。その後、選択した項目を変更すると正しく更新されます。ところで

<Grid Name="lyDetailForm" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="2" Grid.Row="1" Margin="10"> 
    <TextBox Name="tbNif" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Left" Width="100" Margin="5" IsEnabled="{Binding SpId, Converter={x:Static local:SpSentToBooleanConverter.Instance}, ConverterParameter=NEGATE, FallbackValue=False}" Text="{Binding Nif,ValidatesOnExceptions=True,NotifyOnValidationError=True}" Validation.Error="OnEditBoxError"/> 
    <ComboBox Name="cbType" Grid.Column="1" Grid.Row="2" Grid.RowSpan="2" Height="23" HorizontalAlignment="Left" Margin="5" VerticalAlignment="Top" Width="100" IsEnabled="{Binding SpId, Converter={x:Static local:SpSentToBooleanConverter.Instance}, ConverterParameter=NEGATE, FallbackValue=False}" Text="{Binding Type, Mode=TwoWay} ItemsSource="{Binding Types}"/> 
</Grid> 

TypesはストリングString[]の配列を返す同じinvoiceオブジェクトから静的プロパティです。コンボボックスの項目は文字列です。

提案がありますか?前もって感謝します。

+1

私はComboBxがSelectedItemをどこにでもバインディングしているのを見ていません。 –

+0

あなたは正しいです、私は代わりにテキストをバインドしていました。それでも、オブジェクトにデフォルト値を設定するまでは機能しました。これを答えに入れると、私はそれをあなたに与えます。 – SJuan76

+0

いいえ、誰かがテスト/選択されたセマンティクスをよりよく記述するまで待ってください –

答えて

1

あなたはテキストボックスとしてcbTypeコンボボックスを使用していて、これは間違っている、結合Text="{Binding Type, Mode=TwoWay}を削除し、SelectedTypeは、現在選択されているタイプを表すこのSelectedItem={Binding SelectedType}ような何かにComboBoxの選択した項目の結合を設定します。

関連する問題