2011-06-11 38 views
1

不允許這個view`我創建了一個包裝來擴展ObservableCollection<T>包裹的ObservableCollection <T>投擲`「EditItem」當綁定到一個WPF的DataGrid

[Serializable] 
public abstract class ModelCollection<TModel> : ModelCollectionBase, 
    IList<TModel>, INotifyCollectionChanged, INotifyPropertyChanged 
    where TModel : ModelBase<TModel> 
{ 
    private ObservableCollection<TModel> wrappedCollection = new ObservableCollection<TModel>(); 

    // wrapper implementation goes here 
} 

我認爲這是工作的罰款,直到我試圖綁定項目從一個列表到一個DataGrid。

<DataGrid ItemsSource="{Binding /Orders}" AutoGenerateColumns="False"> 
    <DataGrid.Columns> 
    <DataGridTextColumn Header="Order Id" Binding="{Binding OrderId}" /> 
     <DataGridTextColumn Header="Date Time" Width="125" Binding="{Binding DateTime}" /> 
     <DataGridTextColumn Header="Notes" Width="125" Binding="{Binding Notes}" /> 
     <DataGridTextColumn Header="Cost" Width="75" Binding="{Binding Cost}" /> 
    </DataGrid.Columns> 
</DataGrid> 

的項目出現在網格中,但雙擊單元格拋出'EditItem' is not allowed for this view.

,當我和一個普通ObservableCollection<T>取代我ModelCollection<TModel>異常沒有拋出。

我的意圖是允許編輯單元格。我是否在包裝上缺少一個接口?

回答

4

我能夠明確落實IList

[Serializable] 
public abstract class ModelCollection<TModel> : ModelCollectionBase, 
    IList<TModel>, IList, INotifyCollectionChanged, INotifyPropertyChanged 
    where TModel : ModelBase<TModel> 
{ 
    private ObservableCollection<TModel> wrappedCollection = new ObservableCollection<TModel>(); 

    // wrapper implementation goes here 
} 
解決這個問題
相關問題