是否可以将当前的DataContext作为ObjectDataProvider的ContructorParameter传递?(Is it possible to pass current DataCo

编程入门 行业动态 更新时间:2024-10-09 17:23:43
是否可以将当前的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?

更多推荐

本文发布于:2023-08-07 17:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465289.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ObjectDataProvider   DataContext   ContructorParameter   current   pass

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!