2

オブジェクトのリストと、グリッド内のいくつかのフィールドがあります。List( ) 内のオブジェクトが選択されると、Grid ( )lvInvoicesの dataBinding を更新します。lyDetailForm

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の static プロパティで、 string の配列を返します。コンボボックスの項目は文字列です。invoiceString[]

助言がありますか?前もって感謝します。

4

1 に答える 1

1

cbTypeComboBox を TextBox として使用していますが、これは間違っています。Text="{Binding Type, Mode=TwoWay}バインディングを削除し、ComboBox の選択された項目のバインディングを、現在選択されているタイプを表すSelectedItem={Binding SelectedType}このようなものに設定します。SelectedType

于 2012-04-23T09:24:26.250 に答える