0
我試着綁定一個datagrid的selectedItem與MVVM中的一個屬性。 問題是它不會觸發屬性的「設置」。wpf dataGrid綁定selecteditem不工作
在XAML部分我有:
<WPFCtrlDg:ExtDataGrid Name="_edgMessage" Grid.Row="1"
ItemsSource="{Binding Path=LNE_MESSAGE, Mode=OneWay}"
SelectedItem="{Binding Path=CurrentMessage, Mode=TwoWay}">
代碼部分
:
private LNE_MESSAGE _currentMessage;
public LNE_MESSAGE CurrentMessage
{
get
{
if (_currentMessage == null)
{
ICollectionView collectionView = CollectionViewSource.GetDefaultView(LNE_MESSAGE);
if (collectionView != null)
return collectionView.CurrentItem as LNE_MESSAGE;
return null;
}
return _currentMessage;
}
set
{
ICollectionView collectionView = CollectionViewSource.GetDefaultView(LNE_MESSAGE);
if (collectionView != null)
collectionView.MoveCurrentTo(value);
_currentMessage = value;
OnPropertyChanged(() => CurrentMessage);
}
}
的extdatagrid是一個自定義的控制和選擇的項目屬性進行這樣:
public object SelectedItem
{
get { return GetValue(SelectedItemProperty); }
set { SetValue(SelectedItemProperty, value); }
}
public static readonly DependencyProperty SelectedItemProperty =
DependencyProperty.Register("SelectedItem", typeof(object), typeof(ExtDataGrid),
new UIPropertyMetadata((s, e) =>
{
ExtDataGrid extDg = s as ExtDataGrid;
Debug.Assert(extDg != null);
extDg.CurrentItem = e.NewValue;
}));
任何想法如何正確綁定selecteditem屬性?
您可以在調試時看到您的參數的本地窗口請參閱http://blogs.msdn.com/b/zainnab/archive/2010/01/29/using-the-wpf-tree-visualizer- vstipdebug0004.aspx – Martijn
這兩個窗口empy(不知道我是否需要打印輸出的東西)。順便說一句datagrid加載它的內容connrectly與LME_MESSAGE屬性是在相同的viewmodel比CurrentMessage,所以我認爲datacontext是正確的 – andrea
好吧我現在得到它...我會調試,看到..謝謝 – andrea