2015-01-14 3 views
0

나는 이런 식으로 묶인 체크 박스 목록을 가지고 있습니다.바운드 체크 박스 상태가 실행되지 않습니다. 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)); 
    } 
} 
+0

클래스'Something'는 것을 가지고 있다는 것을 의미한다. – Clemens

+0

@ 클레멘스 오, 왜냐하면 ** ** ** ** 2 가지입니다. 맞습니까? 그래도 * OnPropertyChanged * 메소드가 호출 될 것이라고 기대합니다 (체크 박스를 클릭 할 때 적어도 시계에서 수행 할 수있는 * bool * 속성 * Active * 값을 변경할 때). 슬프게도, 아직 효과가 없습니다. 상속하고 * Something * 클래스에 해당하는 것을 구현했습니다. 쿠키가 멀어졌습니다. –

+1

아니요, 양방향이기 때문이 아닙니다. 인터페이스는 속성을 선언하는 클래스 (속성 변경 알림을 보내려는 클래스)에서 구현해야합니다. 'Name'과'Active' 속성은'Something' 클래스에 의해 선언되므로,이 클래스는'INotifyPropertyChanged'를 구현해야합니다. – Clemens

답변

3

클래스 SomethingINotifyPropertyChanged 인터페이스를 구현해야합니다. 이 속성 값이 변경 될 때

public class Something : INotifyPropertyChanged 
{ 
    public event PropertyChangedEventHandler PropertyChanged; 
} 

를 작성 외에 그것은 또한 : 예컨대, 실제로 PropertyChanged 이벤트를 발생하는`INotifyPropertyChanged`을 구현하는

private string name; 
public string Name 
{ 
    get { return name; } 
    set 
    { 
     name = value; 
     OnPropertyChanged(); 
    } 
} 
+0

도구를 자유롭게 수정하여 문제를보다 정확하게 해결할 수 있습니다 (확인란은 거의 수정할 수 없습니다 ** 이름 **). 저것보다, 유피, 그건 문제 였어. –

관련 문제