是否可以将当前的DataContext作为ObjectDataProvider的ContructorParameter传递?(Is it possible to pass current DataContext as ContructorParameter of ObjectDataProvider?)
将DataContext作为DataTemplate的参数传递将非常有用:
<DataTemplate> <DataTemplate.Resources> <ObjectDataProvider x:Key="ServiceDataProvider" ObjectType="{x:Type control:ServiceLayout}"> <ObjectDataProvider.ConstructorParameters> /*here could be DataContext..but how?*/ </ObjectDataProvider.ConstructorParameters> </ObjectDataProvider> </DataTemplate.Resources> <ContentPresenter Content="{Binding Source={StaticResource ServiceDataProvider}}" /> </DataTemplate>我将在ListBox ItemTemplate中使用此DataTemplate。 那么,DataContext将是ListBoxItem绑定对象(类型已知)
可能有任何其他方法从DataTemplate传递参数到构造函数?
It would be very useful to pass DataContext as parameter for DataTemplate:
<DataTemplate> <DataTemplate.Resources> <ObjectDataProvider x:Key="ServiceDataProvider" ObjectType="{x:Type control:ServiceLayout}"> <ObjectDataProvider.ConstructorParameters> /*here could be DataContext..but how?*/ </ObjectDataProvider.ConstructorParameters> </ObjectDataProvider> </DataTemplate.Resources> <ContentPresenter Content="{Binding Source={StaticResource ServiceDataProvider}}" /> </DataTemplate>I will use this DataTemplate in ListBox ItemTemplate. So, DataContext will be ListBoxItem bound object (type is known)
May be there are any other ways to pass parameter to constructor from DataTemplate?
最满意答案
感谢Magnus(MM8)的答案: 是否可以将当前的DataContext作为ObjectDataProvider的ContructorParameter传递?
Thanks to Magnus (MM8) for the answer here: Is it possible to pass current DataContext as ContructorParameter of ObjectDataProvider?
更多推荐
发布评论