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