나는 이런 식으로 묶인 체크 박스 목록을 가지고 있습니다.바운드 체크 박스 상태가 실행되지 않습니다. OnPropertyChanged
<ListBox ItemsSource="{Binding AllThings}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Name}"
IsChecked="{Binding Active,Mode=TwoWay}"
Checked="ToggleButton_OnChecked"
Unchecked="ToggleButton_OnUnchecked"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
바인딩은 단방향으로 작동합니다. 처음부터 내 설정에 따라 상자를 선택/선택 취소 할 수 있기 때문입니다. 기본 뷰 모델을 업데이트하기 위해 상자를 검사 할 것을 기대했지만 그럴 수 없습니다. OnPropertyChanged에 설정된 중단 점에 도달하지 않습니다. 나는 그것이 내가 속성을 변경하고 있다는 사실과 관련이 있다고 생각한다. 관찰 된 속성이지만 무지 때문에 나는 확실하지 않다.
class Presenter : INotifyPropertyChanged
{
private IEnumerable<Something> _allThings;
public IEnumerable<Something> AllThings
{
get { return _allThings; }
set
{
_allThings = value;
OnPropertyChanged("AllThings");
}
}
public Presenter()
{
_allThings = DataAccessor.GetThings();
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(
[CallerMemberName] String propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
무엇이 여기에 누락 될 수 있습니까?
제가 알기로는 정확하게as this guy suggests입니다. 분명히 뭔가를보고 싶어하지만, 나는 또한 Soomething 클래스의 인터페이스를 구현 무엇 ... @Clemens에서
편집 요청에 따라
을 내 능력 밖입니다.
public class Something :INotifyPropertyChanged
{
public int Id { get; set; }
public String Name { get; set; }
public bool Active { get; set; }
public override String ToString()
{
return Name;
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(
[CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
클래스'Something'는 것을 가지고 있다는 것을 의미한다. – Clemens
@ 클레멘스 오, 왜냐하면 ** ** ** ** 2 가지입니다. 맞습니까? 그래도 * OnPropertyChanged * 메소드가 호출 될 것이라고 기대합니다 (체크 박스를 클릭 할 때 적어도 시계에서 수행 할 수있는 * bool * 속성 * Active * 값을 변경할 때). 슬프게도, 아직 효과가 없습니다. 상속하고 * Something * 클래스에 해당하는 것을 구현했습니다. 쿠키가 멀어졌습니다. –
아니요, 양방향이기 때문이 아닙니다. 인터페이스는 속성을 선언하는 클래스 (속성 변경 알림을 보내려는 클래스)에서 구현해야합니다. 'Name'과'Active' 속성은'Something' 클래스에 의해 선언되므로,이 클래스는'INotifyPropertyChanged'를 구현해야합니다. – Clemens