【问题标题】:How to update control inside ListBox item如何更新 ListBox 项内的控件
【发布时间】:2013-07-20 05:38:27
【问题描述】:

我有一个ListBox 定义如下。我在ListView 项目中有CheckBox,需要以编程方式选中/取消选中(只是想实现全选/取消全选操作)。实现这一目标的最佳方法是什么?

<ListBox Margin="0,0,10,0" Name="listViewChanges" SelectionMode="Multiple">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                <CheckBox x:Name="lblChangedSelected" IsChecked="{Binding Selected}" VerticalAlignment="Center" VerticalContentAlignment="Center" Margin="10,0,0,0"></CheckBox>
                <Label x:Name="lblChangedStatus" Content="{Binding Status}" VerticalContentAlignment="Center"></Label>
                <Label x:Name="lblChangedPath" Content="{Binding Path}" VerticalContentAlignment="Center"></Label>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

【问题讨论】:

    标签: c# wpf xaml checkbox listbox


    【解决方案1】:

    您应该拥有绑定实现INotifyPropertyChanged 后面的类。然后,当您更改属性时,触发NotifyPropertyChanged 事件,绑定应该会自动更新。

    【讨论】:

    • 我是 WPF 新手。你能提供一些资源/链接吗?
    • 这不是 WPF 特定的(至少不是关于 INotifyPropertyChanged 的部分)。试试这个:stackoverflow.com/questions/6789236/…
    猜你喜欢
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 2014-07-06
    • 1970-01-01
    • 2011-07-14
    • 2014-11-26
    • 1970-01-01
    相关资源
    最近更新 更多