日期:2014-05-20  浏览次数:20950 次

WPF DataGrid 绑定到 ObservableCollection 没有反应
我创建了一个用户控件。名字为nodesSetCtrl
列表的源,绑定到用户控件本身的NVS4Binding.NodeList
NodeList的类型为ObservableCollection<Node>
 <DataGrid Name="dtgNodesInfo" 
ItemsSource="{Binding ElementName=nodesSetCtrl, 
                      Path=NVS4Binding.NodeList, 
                      Converter={StaticResource testConverter}}">
</DataGrid>


其中testConverter的代码如下:对绑定进行测试。
class TestConverter : IValueConverter
    {
        public object Convert(object values, Type targetType, object parameter, CultureInfo culture)
        {
            Debug.WriteLine("Binding is in");
            return values;//断点
        }
        public object ConvertBack(object value, Type targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


然后对于DataGrid的列为:

 <DataGrid.Columns>
                <DataGridTextColumn Header="网络号" 
                                    Binding="{Binding Path=Net, 
                                                      Converter={StaticResource testConverter}}"/> 
                <DataGridTextColumn Header="短地址" 
                                    Binding="{Binding Path=Address, 
                                                      Converter={StaticResource testConverter}}"/>
</DataGrid.Columns>


其中的Net,Address分别为Node的属性。
在运行时发现DataGrid的绑定是对的。断点处可以获得节点列表。有20个Node数据。
但是<DataGrid.Columns>的绑定不会命中断点。列表没有数据显示出来。
我给Node中的Net和Address都实现了INotifyPropertyChanged接口。还是不行。
有没有人做过这类的绑定。求指点。。。。。。。

------解决方案--------------------
贴出来你的NodesSetCtrl以及Node类看看