WPF数据网格中的数据绑定(C#4.0)

WPF数据网格中的数据绑定(C#4.0),c#,wpf,data-binding,wpfdatagrid,C#,Wpf,Data Binding,Wpfdatagrid,我只是在玩WPF,我在数据绑定方面有问题 这是我到目前为止的代码 窗口XAML: <Window x:Class="FRC.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Registry Cleaner - By

我只是在玩WPF,我在数据绑定方面有问题

这是我到目前为止的代码

窗口XAML:

<Window x:Class="FRC.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Registry Cleaner - By Martin Milan." MinHeight ="350" Height ="350" MinWidth="525" MaxHeight="700" Width="350" Background="#FFC199AA" >
    <DockPanel Background="#FFD9E1E8" Margin="10">
        <Grid DockPanel.Dock="Top"  >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
            </Grid.RowDefinitions>
            <Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" >Filepath:</Label>
            <TextBox Grid.Column="1" HorizontalAlignment="Stretch" Name="txtFilePath" VerticalAlignment="Stretch" />
        </Grid>
        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right" >
            <Button Name="butScan" Content="Scan" MinWidth="75" Margin="0,0,10,5" />
            <Button Name="butDelete" Content="Remove RegKeys" Margin="0,0,5,5" Click="butDelete_Click" />  
        </StackPanel>
        <ScrollViewer Margin="0,0,0,5">
            <DataGrid AutoGenerateColumns="False" Name="dgActions" CanUserAddRows="False" CanUserDeleteRows="False" >
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding RegKeyPath, Mode=OneWay}" Header="Registry Key" Width="*"/>
                    <DataGridCheckBoxColumn Binding="{Binding DeletePath, Mode=TwoWay}" Header="Can I delete key?" 
                                            MinWidth="110" Width="110" />
                </DataGrid.Columns>
            </DataGrid>    
        </ScrollViewer>

    </DockPanel>
</Window>
基本上。它设置RegistryAction对象的列表,并将其与DataGrid绑定。然而,我发现每当我在butDelete_中运行代码时,尽管列表已更新,但网格上的内容并未得到更新

简言之,有人能认出我错过了什么吗


Martin。

您需要执行
注册表操作。MSDN还有一个。

mRegistryActions
应该是
observedcollection

protected ObservableCollection<RegistryAction> mRegistryActions = new ObservableCollection<RegistryAction>();
protectedobservedcollection mRegistryActions=newobservedcollection();

一次犯规就彻底解决了问题-干杯。应该想到的是,如果网格没有听到集合中的更改,那么可能集合没有大声谈论这些更改+1并接受。+1-干杯。。。INotifyCollectionCHange也需要在列表中进行更改-当然,我总是可以在子类中进行更改。。。
namespace FRC
{
    public class RegistryAction
    {
        public string RegKeyPath { get; set; }
        public bool DeletePath { get; set; }
        public RegistryAction()
        {
            this.DeletePath = false;
            this.RegKeyPath = "";
        }
    }
}
protected ObservableCollection<RegistryAction> mRegistryActions = new ObservableCollection<RegistryAction>();