개체 목록과 Grid 안에 몇 개의 필드가 있습니다. 목록 (lvInvoices
)에서 객체가 선택되면, 나는 그리드 (lyDetailForm
)의 데이터 바인딩 업데이트 :Combobox가 초기 개체 값을 반영하지 않습니다.
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에 바인딩되어있는 것을보고 싶지 않습니다. –
네 말이 맞아, 나는 대신 Text를 구속했다. 그러나 객체에 대한 기본값을 설정하기 전까지 작동했습니다. 이걸 답으로 써 주면 내가 너에게 그것을 줄 것이다. – SJuan76
아니요, 테스트/선택된 의미를 더 잘 설명 할 때까지 기다리십시오. –