重新选中WPF列表视图中的复选框

时间:2012-02-18 13:14:26

标签: c# wpf listview mvvm checkbox

我有一个带有listview的向导(列出学生名),列表视图在第1列中有用于选择学生的复选框,当移动到下一页并返回上一页时,复选框中的检查消失了。但具有IsStudentChecked属性的列表框的observableCollection为true,与复选框绑定。

public class StudentDetails
    {
    bool _IsChecked;
    public bool IsChecked
    {
     get { return _IsChecked; }
     set { _IsChecked = value;PropertyChanged(this, new PropertyChangedEventArgs(IsChecked)); }
    }
    string _StudentName;
    public string StudentName
    {
     get { return _StudentName; }
     set { _StudentName = value; PropertyChanged(this, new PropertyChangedEventArgs(StudentName));}
    }



<CheckBox Name="chkSelectStudent" HorizontalAlignment="Center" VerticalAlignment="Center" 
                          IsChecked="{Binding Path= IsChecked,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" >



<ListView IsSynchronizedWithCurrentItem="True" x:Name="listStudentNames
                   ItemsSource="{Binding Path=StudentList, Mode=TwoWay}" ScrollViewer.HorizontalScrollBarVisibility="Hidden"                  
                 Grid.Column="1" Margin="0,-4,0,-5">          
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="45" Header="Select" CellTemplate="{DynamicResource StudentSelectTemplate}" />
                    <GridViewColumn Width="170" Header="Student Name" DisplayMemberBinding="{Binding StudentName}"/>
                </GridView>
            </ListView.View>
        </ListView>

0 个答案:

没有答案