DataGrid binding problem

Sep 29, 2010 at 11:20 AM

Hi,

I have the following object and ObservableCollection

   public class PlantItem : INotifyPropertyChanged
    {
        public String Id 
        {
            get { return id; }
            set
            {
                if (value != id)
                {
                    id = value;
                    Notify("Id");
                }
            }
        }
        private string id;

        public String Description 
        {
            get { return description; }
            set
            {
                if (value != id)
                {
                    id = value;
                    Notify("Description");
                }
            }
        }
        private string description; 
        #region INotifyPropertyChanged Members

        protected void Notify(String PropertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }

    public class PlantManifest : ObservableCollection<PlantItem>
    {
        public PlantManifest()
        {
        }     
    } }

And the following DataGrid:

            <dg:DataGrid x:Name="ManifestGrid" ItemsSource="{Binding Path=Manifest, Mode=TwoWay}"
                         AutoGenerateColumns="False">
                <dg:DataGrid.Columns>
                    <dg:DataGridTextColumn Header="Id" Width="185" Binding="{Binding Path=Id, Mode=TwoWay}"/>
                    <dg:DataGridTextColumn Header="Description" Width="200"  Binding="{Binding Path=Description, Mode=TwoWay}"/>
                </dg:DataGrid.Columns>
            </dg:DataGrid>

Which is bound to "Manifest" which is a DP in the code-behind, defined as follows:

        public PlantManifest Manifest
        {
            get { return (PlantManifest)GetValue(ManifestProperty); }
            set { SetValue(ManifestProperty, value); }
        }
        public static readonly DependencyProperty ManifestProperty =
            DependencyProperty.Register("Manifest", typeof(PlantManifest), typeof(ManifestEditor), new PropertyMetadata(OnManifestChanged));

        private static void OnManifestChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
        {
             Debug.WriteLine("Foo");
        }

I can see the datagrid populated with my manifest data, but if I edit any of the cells, altghough I can see the setters on the PlantItem properties get called as expected, OnManifestChanged never gets called. I've got a feeling I'm not doing enough notifying somewhere but can anyone help me?

 

Rich