【发布时间】:2017-05-17 08:27:52
【问题描述】:
是否可以使用我在另一个 UserControl 中定义的资源,而无需为 ResourceDictionary 使用额外的文件。
我有一个用户控件“ViewCostumers”,并在其中定义了一个包含所有客户的 ListView 的 DataTemplate。 现在我编写了一个 UserCotnrol“ViewOverview”,其中应该出现相同的 ListView。如果可能的话,我想将 LsitView 保留在文件“ViewCostumer”中。
提前致谢
编辑: 我试图做的是将 DataTempalte/ListView 保留在原始文件中。然后我想从另一个文件(如资源字典,只有 ViewCostumer 是一个 UserControl)中引用该文件(这是一个 UserControl):
< ResourceDictionary>
< ResourceDictionary.MergedDictionaries>
< ResourceDictionary Source="View/ViewCostumer.xaml" />
< /ResourceDictionary.MergedDictionaries>
< /ResourceDictionary>
【问题讨论】:
-
资源是通过它们的键来引用的,所以任何你想使用资源的地方只要把键放在你的代码中就可以了……你可以使用的次数没有限制相同的键。
标签: c# wpf xaml user-controls resourcedictionary