我想将DataGrid
SelectedItem
用户控件内部的a绑定到a DependencyProperty
,这是我的代码:
在用户控件(DataGridControl
)中:
public static readonly DependencyProperty DataGridSelectedItemProperty
= DependencyProperty.Register(
"DataGridSelectedItem"
, typeof(object)
, typeof(DataGridSelectorControl)
, new UIPropertyMetadata(null));
public object DataGridSelectedItem
{
get { return (object)GetValue(DataGridSelectedItemProperty); }
set { SetValue(DataGridSelectedItemProperty, value); }
}
<DataGrid ItemsSource="{Binding Source={StaticResource theSource}}"
SelectedItem="{Binding ElementName=DataGridControl,Path=DataGridSelectedItem,UpdateSourceTrigger=PropertyChanged}" />
在视图模型中:
object projectSelectedItem;
public object ProjectSelectedItem
{
get
{
return projectSelectedItem;
}
set
{
projectSelectedItem = value;
RaisePropertyChanged("ProjectSelectedItem");
}
}
并认为:
<MvvmCommonControl:DataGridControl DataGridSelectedItem="{Binding ProjectSelectedItem}" DataGridDataCollection="{Binding DataCollection}"/>
但它不起作用!