【发布时间】:2015-01-13 00:29:44
【问题描述】:
所以,我在 Visual Studio 中创建了一个 UI,并且由于所有重复的元素,我在我的用户控件的资源部分中使用了很多元素。我要做的是使用文件中的另一个 StaticResource 作为项目的模板来遍历项目。
问题在于Datatemplate 当然会将DataContext 切换到它正在迭代的项目。所以我试图弄清楚如何获取静态资源的上下文,它位于UserControl 的上下文中。我考虑过使用相对采购,但后来意识到StaticResource 没有该选项,只能让您访问上下文的资源。
有什么建议可以在这里做什么?
<Style TargetType="ItemsControl" x:Key="BeneficiaryList">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Expander Header="{Binding Name_1}">
<Expander.Resources>
<utils:BindingProxy x:Key="proxy" Data="{Binding}"/>
</Expander.Resources>
<!--Attempt at a proxy binding to access another style resource in the file. Does not work.-->
<ContentControl Style="{StaticResource proxy.Person_Template}"/>
</Expander>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
谢谢!
【问题讨论】:
标签: c# wpf xaml mvvm caliburn.micro