저는 WPF를 처음 사용하고 있으며 사용자 지정 개체 목록으로 ListView를 채우려는 경우 몇 가지 어려움이 있습니다.WPF 데이터 바인딩 문제
internal class ApplicationCode
{
public int Code { get; set; }
public IEnumerable<string> InstrumentCodes { get; set; }
}
ListView에 ItemsSource로 설정 한 ApplicationCode 목록이 있습니다. ApplicationCode.Code를 문자열로 표시하고 나머지 열에 대해서는 열 이름이 InstrumentCodes 컬렉션에 포함되어 있는지 여부에 따라 선택/선택 해제 할 수있는 확인란을 표시해야합니다. 나는 데이터 바인딩에 변환기를 사용 확인란을 설정하기 위해
: 나는 바인딩 셀 데이터의 시점에서 현재 열이 알고 내가 할 수 없기 때문에
<DataTemplate x:Key="InstrumentCodeTemplate">
<CheckBox IsEnabled="False" IsChecked="{Binding Mode=OneTime, Converter={StaticResource InstrumentSelectionConverter}}" />
</DataTemplate>
내가 가진 문제는 ConverterParameter를 설정할 수 없습니다.
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
ApplicationCode appCode = value as ApplicationCode;
return appCode != null && appCode.InstrumentCodes.Contains(parameter.ToString());
}
작은 예 :
Id | Code1 | Code3 | Code4
--------------------------------
123 | True | False | True
데이터 행 1 : ApplicationCode.InstrumentCodes {코드 1, Code4}
열 인덱스 또는 이름을 찾을 수있는 방법이 있습니까? 아니면이 문제를 해결할 다른 방법이 있습니까?
ListView 바인딩을위한 XAML 코드는 무엇입니까? –
안녕 마틴. 바인딩은 코드 뒤에 작성됩니다. AcnList.ItemsSource = repository.GetApplicationCodes(); GetApplicationCodes가 List를 반환합니다. –
Costin