2014-01-23 6 views
0

를 통해 ItemsSource 결박 :혼합/XAML : 나는 윈도우 8.1 응용 프로그램을 만들고 다음 코드가 있어요 버튼

<ListView x:Name="listView" Height="505" Canvas.Left="35" Canvas.Top="75" Width="300" ItemTemplate="{StaticResource GroupTemplate}" ItemsSource="{Binding Groups, Mode=TwoWay, UpdateSourceTrigger=Explicit}" HorizontalAlignment="Left" VerticalAlignment="Top" UseLayoutRounding="False" ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionMode="None" /> 

<Button Height="40" Width="260" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="40" Canvas.Top="585" BorderThickness="0" Content="Overige tonen" Background="#FF9B9B9B" Style="{StaticResource ButtonStyle1}" Click="show_items2" /> 

사용자가 show_items2 버튼을 클릭의 ItemsSource 그룹이 다른 ItemsSource로 대체되어야한다.

private void show_Medicatie2(object sender, RoutedEventArgs e) 
     { 
      // replace itemsSource with another 
     } 

내가 해봤 많은 자습서 아무것도하지만, 솔기 작업 : 나는 아래의 버튼에 대한 매우 명백 코드를 가지고 비주얼 스튜디오 2013에 대한 혼합에서 샘플 데이터 '그룹'을 사용합니다. 내가 놓친 게 있니? 도움말 정말 고맙습니다. 고맙습니다! 당신이 Groups

답변

0

당신은 RaisePropertyChanged("Groups") 필요 (귀하의 경우를 Groups의 소유자)는 명시 적으로 WPF 말할 수 그래서 INotifyPropertyChanged을 할 필요가있다 그 바인딩은 새로 고침이 필요합니다. DependencyProperties을 사용하지 않는 경우 요구 사항입니다.

클래스 정의에이 추가 :

class X : System.ComponentModel.INotifyPropertyChanged 
{ 
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; 

    public IEnumerable<object> Groups //Replace 'object' with the type your are using... 
    { 
     get{ return m_Groups; } 
     set 
     { 
      m_Groups = value; 

      //Raise the event to notify that the property has actually got a new value 
      var handler = PropertyChanged; 
      if(handler != null) 
       PropertyChanged(this, new PropertyChangedEventArgs("Groups")); 
     } 
    } IEnumerable<object> m_Groups = new List<object>(); 
} 

왜이 일을 하는가?

는 WPF를 사용하면 바인딩 소스로 개체를 사용할 때 인터페이스를 구현하는 경우에 대한 INotifyPropertyChanged하고, WPF는 확인 알고있다. 이 경우 WPF는 이벤트를 구독합니다. 이벤트가 트리거되면 특성 이름이 점검되고 바인딩 경로의 마지막 특성 인 과 일치하면 바인딩이 업데이트됩니다.

IEnumerable<T>ObservableCollection<T>으로 바꿀 수도 있지만 곧 이후에 일이 까다로워지기 시작합니다. 나는 ObservableCollection<T>에 대해 읽는 것이 좋습니다!

0

당신이 바인딩 클래스 변경하면