저는 WPF와 Binding에 아직 익숙하지 않으므로 가능한 구체적으로 작성하십시오. 내가 콤보 상자와 바인딩하려는 checkBoxes의 ListBox 개체의 목록을 작성하려고합니다. 콤보 상자를 선택하면 ListBox의 ListBox를 새로 고치고 싶습니다. ListBox는 첫 번째로드에서 완벽하게로드되지만 객체 목록이 변경되면 새로 고치지 않습니다. 디버깅을했는데 UI가 트리거되지 않고 객체가 그것을 변경하고 있음을 알 수 있습니다. 어떤 도움이라도 좋을 것입니다. 미리 감사드립니다.WPF Checklist ComboBox로 바인딩 선택
콤보
<ComboBox Grid.Column="0" SelectionChanged="JobTypeComboBox_SelectionChanged"
Name="JobTypeComboBox"
ItemsSource="{Binding Path=AllJobTypes}"
DisplayMemberPath="Name"
SelectedValuePath="Name"
SelectedValue="{Binding Path=JobConfig.SelectedJobType.Name}" />
리스트 박스에 체크 박스
<ListBox ItemsSource="{Binding AllDocTypes}" Height="177" Name="listTopics" VerticalAlignment="Top">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<CheckBox Content="{Binding Name}" IsChecked="{Binding IsChecked}" Checked="DocTypeCheckBox_Checked" Unchecked="DocTypeCheckBox_UnChecked"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
생성자
public ConfigControl() {
InitializeComponent();
this.DataContext = this;
LoadSettings();
}
는
// Create the OnPropertyChanged method to raise the event
protected void OnPropertyChanged(string name) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public JobConfiguration JobConfig {
get { return _jobConfig; }
set {
_jobConfig = value;
// Call OnPropertyChanged whenever the property is updated
OnPropertyChanged("JobConfig");
}
}
public DocTypeList AllDocTypes {
get { return _allDocTypes; }
set {
_allDocTypes = value;
OnPropertyChanged("AllDocTypes");
}
}
특성
콤보 변경을 선택
private void JobTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
//set the new jobtype selected
//load settings for that job type
ComboBox cmb = sender as ComboBox;
JobType selectedJob = (JobType)cmb.SelectedItem;
JobConfig.SelectedJobType = selectedJob;
AllDocTypes.SetDocTypeIsChecked(JobConfig.SelectedJobType.DocTypes);
OnPropertyChanged("JobConfig");
OnPropertyChanged("AllDocTypes");
}
의 DOCTYPE 클래스
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
namespace ISO_Validation_And_Processing.Models {
public class DocType {
[XmlElement]
public string Name { get; set; }
[XmlIgnore]
public bool IsChecked { get; set; } = false;
}
public class DocTypeList : List<DocType> {
public static DocTypeList Read(ISerializeManager serializeManager) {
if (serializeManager != null) {
return serializeManager.ReadObject<DocTypeList>();
} else {
return null;
}
}
public DocTypeList() { }
public void SetDocTypeIsChecked(DocTypeList selectedDocs) {
foreach (var docType in this) {
docType.IsChecked = IsDocTypeSelected(docType, selectedDocs);
}
}
public bool IsDocTypeSelected(DocType docType, DocTypeList selectedDocs) {
//if there is a doctype with the same name return true
return selectedDocs.Where(t => t.Name == docType.Name).ToList().Count > 0;
}
}
}
AllDocTypes는 어떻게 그리고 어디서 "새로 고침"됩니까? – mm8
'AllDocTypes'는 ObservableCollection <>입니까? – MisterMystery
죄송합니다. 생성자를 추가했습니다. –