我有一个对象列表,以及网格内的一些字段。当 List( lvInvoices
) 中的一个对象被选中时,我更新了 Grid( 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
是来自同一invoice
对象的静态属性,它返回一个字符串数组String[]
。组合框项目是字符串。
有什么建议么?提前致谢。