グリッド内にオブジェクトのリストといくつかのフィールドがあります。リスト(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
オブジェクトから静的プロパティです。コンボボックスの項目は文字列です。
提案がありますか?前もって感謝します。
私はComboBxがSelectedItemをどこにでもバインディングしているのを見ていません。 –
あなたは正しいです、私は代わりにテキストをバインドしていました。それでも、オブジェクトにデフォルト値を設定するまでは機能しました。これを答えに入れると、私はそれをあなたに与えます。 – SJuan76
いいえ、誰かがテスト/選択されたセマンティクスをよりよく記述するまで待ってください –