首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

ObservableCollection集合绑定有关问题

2013-01-02 
ObservableCollection集合绑定问题绑定 了DataGrid 删除时数据删除了但DataGrid不能更新 ObservableCollec

ObservableCollection集合绑定问题
绑定 了DataGrid 删除时  数据删除了但DataGrid不能更新

 ObservableCollection<InternalUsersArticleTb> article = new ObservableCollection<InternalUsersArticleTb>();
        InternalUsersArticleTb iarticle = null;
        public ObservableCollection<InternalUsersArticleTb> GetPopulation(String Condition)
        {
            MainDataGrid.ItemsSource = null;
            dataPager1.Source = null;
            var list = new ObservableCollection<InternalUsersArticleTb>();
            TextReader txtReader = new StringReader(Condition);
            XElement doc = XElement.Load(txtReader);
            var ban = (from el in doc.Elements()
                       select new InternalUsersArticleTb
                       {
                           ArticleID = el.Element("ArticleID").Value.Trim(),
                           ArticleTitle = el.Element("ArticleTitle").Value.Trim(),
                           ArticleContent = cleanString(el.Element("ArticleContent").Value.Trim().Length < 20 ? el.Element("ArticleContent").Value.Trim() : el.Element("ArticleContent").Value.Trim().Substring(0, 20)).Trim().ToString() + "...",
                           PublishDate = DateTime.Parse(el.Element("PublishDate").Value),
                           CollectionDate = DateTime.Parse(el.Element("CollectionDate").Value),
                           ArticleSource = el.Element("ArticleSource").Value.Trim(),
                           ArticleUrl = el.Element("ArticleUrl").Value.Trim(),
                           Author = el.Element("Author").Value.Trim(),
                           MediaAddress = el.Element("MediaAddress").Value.Trim(),
                           Score = el.Element("Score").Value.Trim(),


                           ArticlesCategoryText = el.Element("ArticlesCategoryText").Value.Trim(),
                           IsEnabled = el.Element("IsEnabled").Value.Trim(),
                           IsAllowReview = el.Element("IsAllowReview").Value.Trim()
                        
                       }
                   );

            return new ObservableCollection<InternalUsersArticleTb>(ban.ToList());
        }

iarticle = this.MainDataGrid.SelectedItem as FloatingWindowControl.InternalUsersArticleTb;
article.Remove(iarticle);


 <data:DataGrid x:Name="MainDataGrid" SelectionChanged="MainDataGrid_SelectionChanged"  AutoGenerateColumns="False" ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" Style="{StaticResource Summary_DataGridStyle}" RowStyle="{StaticResource DataGridRowStyle}" BorderBrush="{x:Null}" VerticalGridLinesBrush="{x:Null}" AlternatingRowBackground="Transparent" HorizontalGridLinesBrush="{x:Null}" RowBackground="#AAE0E0E0" GridLinesVisibility="None" Foreground="#FF5A5A5A" CellStyle="{StaticResource DataGridCellStyle3}">
                <data:DataGrid.Columns>
                    <data:DataGridTextColumn Binding="{Binding ArticleID, Mode=TwoWay}" Header="ID" Width="0.2*"  CellStyle="{StaticResource DataGridCellStyle2}" EditingElementStyle="{StaticResource Column-TextBoxStyle}"/>
                    <data:DataGridTextColumn Binding="{Binding ArticleTitle, Mode=TwoWay}" Header="标题" Width="0.6*"/>
                    <data:DataGridTextColumn Binding="{Binding ArticleContent, Mode=TwoWay}" Header="内容" Width="1.0*"/>
                    <data:DataGridTextColumn Binding="{Binding PublishDate, Mode=TwoWay}" Header="发布时间" Width="0.4*"/>
                    <data:DataGridTextColumn Binding="{Binding ArticleSource, Mode=TwoWay}" Header="文章来源" Width="0.3*"/>
                    <data:DataGridTextColumn Binding="{Binding ArticleUrl, Mode=TwoWay}" Header="文章地址" Width="0.4*"/>
                    <data:DataGridTextColumn Binding="{Binding Author, Mode=TwoWay}" Header="作者" Width="0.2*"/>


                    <data:DataGridTextColumn Binding="{Binding MediaAddress, Mode=TwoWay}" Header="媒体地址" Width="0.35*"/>
                    <data:DataGridTextColumn Binding="{Binding Score, Mode=TwoWay}" Header="评分" Width="0.2*"/>
                    <data:DataGridTextColumn Binding="{Binding ArticlesCategoryText, Mode=TwoWay}" Header="分类" Width="0.3*"/>
                    <data:DataGridTextColumn Binding="{Binding IsEnabled, Mode=TwoWay}" Header="是否启用" Width="0.3*"/>
                    <data:DataGridTextColumn Binding="{Binding IsAllowReview, Mode=TwoWay}" Header="是否评论" Width="0.6*"/>
                </data:DataGrid.Columns>
            </data:DataGrid>


[解决办法]
你可以参考:http://www.cnblogs.com/chengxingliang/archive/2011/07/18/2108732.html

热点排行