日期:2014-05-17  浏览次数:20851 次

求助,ListView如何修改绑定后的数据
XAML 定义了一个listview

<ListView x:Name="lvwFeeds" SelectionMode="Single" ItemsSource="{Binding Mode=TwoWay}" HorizontalAlignment="Left" Height="412" Margin="129,63,0,0" VerticalAlignment="Top" Width="1109" Grid.Row="1" Foreground="Black">
        <ListView.ItemTemplate>
                <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                                <TextBox Height="50" TextWrapping="Wrap" Text="{Binding Title}" Width="300"/>
                                <TextBox Height="50" TextWrapping="Wrap" Text="{Binding Url}" Width="800"/>
                                <TextBlock Height="50" Width="100" Style="{StaticResource PageHeaderTextStyle}"></TextBlock>
                        </StackPanel>
                </DataTemplate>
        </ListView.ItemTemplate>
</ListView>


C#
在LoadState中调用以下方法
private async void LoadFeedsFromFile()
{
        _categoryHelper.Get_all_categories();
        foreach (Category category in _categoryHelper.Categories)
        {
                feeds.Add(new FeedCategory(category.Url, category.Name));
        }
        lvwFeeds.DataContext = feeds;
}


数据可正常显示,我修改了listview中的信息后,保存,后台取不到更改后的模型或listview的值
private void btnSaveItem_Click(object sender, RoutedEventArgs e)
{
        List<Category> categories = new List<Category>();
        // 取模型中的值取不到
        foreach (FeedCategory feed in feeds)
        {
                Category category = new Category();
                category.Name = feed.Title;
                category.Url = feed.Url;
                category.Visible = true;
          &nb