1

I made a datagrid that has for source a ObservableCollection of Entity framework objects. The Datagrid fills well. When I edit a row I don't see the model change with the debugger or in the database when I save with a save button.

Here's my XAML code.

<Window.DataContext>
    <ViewModels:BicycleViewModelCollection />
</Window.DataContext>
 <DataGrid AutoGenerateColumns="True" ColumnWidth="*" ItemsSource="{Binding Bicycles, Mode=TwoWay}" SelectionUnit="FullRow"/>

ViewModelCollection

/// <summary>
/// Collection of BicycleViewModel
/// </summary>
public class BicycleViewModelCollection
{
    /// <summary>
    /// Initializes a new instance of the <see cref="BicycleViewModelCollection"/> class.
    /// </summary>
    public BicycleViewModelCollection()
    {
        var bicycleShop = new BicycleShop();
        bicycleShop.Bicycles.Load();
        this.Bicycles = bicycleShop.Bicycles.Local;
    }

    /// <summary>
    /// Gets or sets the bicycles.
    /// </summary>
    /// <value>
    /// The bicycles.
    /// </value>
    public ObservableCollection<Xav.Entity.Models.Bicycle> Bicycles { get; set; }
}

Note that I use the Local property. I don't know if this is evil or not.

4

0 回答 0