WPF 프로젝트 및 MVVM에서 작업하고 있습니다. 콤보 상자 바인딩 값을 새로 고치는 문제가 있습니다. 그래서, 여기에 그것의 경우, 나는 그리드에 콤보 박스와 버튼을 가지고있다. 선택한 하나의 단계에 따라 새 값을 보려면 데이터 소스를 변경 한 다음 새로 고침해야합니다.MVVM 업데이트 콤보 상자 항목 소스 및 새로 고침
다음 버튼을 좋아하는 가장 좋은 방법은 무엇입니까? 그 후에 이전 버튼을 좋아할 필요가있을 수 있습니다.
public MyScriptForm(IMyScriptModel viewModel) {
this.Model=viewModel;
InitializeComponent();
Height=Double.NaN;
Width=Double.NaN;
}
public IMyScriptModel Model {
get {
return this.DataContext as IMyScriptModel;
}
set {
this.DataContext=value;
}
}
private void btnNext_Click(object sender,
RoutedEventArgs e) {
/// to what ?
Model.cbxAnswer.Clear();
Model.cbxAnswer.add("Step2Data");
}
Create{//its a huge project, this working on when this form created
myScript.Model.cbxAnswer.Add("1");
myScript.Model.cbxAnswer.Add("2");
myScript.Model.cbxAnswer.Add("3");
}
destroy{}
////////////////////////
//Onmy model
public List<string> cbxAnswer {
get {
return m_cbxAnswer;
}
set {
m_cbxAnswer=value;
OnPropertyChanged("cbxAnswer");
}
}
public List<string> m_cbxAnswer=new List<string>();
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName) {
if (PropertyChanged !=null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
XAML :
<Grid>
<ComboBox Name="cbxAnswer" HorizontalAlignment="Left" Margin="10,130,0,0" VerticalAlignment="Top" Width="130" Height="25" ItemsSource="{Binding Path=cbxAnswer}" />
<Button Name="btnNext" HorizontalAlignment="Left" Margin="215,130,0,0" VerticalAlignment="Top" Width="75" Content="İlerle" Click="btnNext_Click" />
</Grid>
안녕하세요, 내 모델은 Imyscriptmodel과 같은 인터페이스를 구현합니다. 그런 다음 해당 인터페이스에서 내 목록을 정의한 다음 내 모델 (imp 포함)에 List와 같이 정의했습니다. cbxAnswer {get; 세트; }. observableCollection을 정의하고 combobox의 itemsSource에 바인드하는 것이 올바른 방법입니까? 예 : // ObservableCollection cbxAnswer {get; set;} // –
@ user3064819 예, 추가/제거가 UI로 전파되지 않습니다. * 전체 * 작업을 새로 고치려면'PropertyChanged'를 올릴 필요가 있습니다. – BradleyDotNET
신의 축복 이여! ObservableCollection 내 완전히 문제를 해결 :) –