我有一个外部库来保存所有主题,在这些主题中我为PlainViews定义了一个样式。扩展viewbase的plainview类位于另一个项目中。我的应用程序无法加载plainview的xaml。它似乎找不到与PlainView关联的资源it
下面是定义plainview的xaml
<Style x:Key="{ComponentResourceKey
TypeInTargetAssembly={x:Type Common:PlainView},
ResourceId= PlainViewRsx}"
TargetType="{x:Type ListView}"
BasedOn="{StaticResource {x:Type ListBox}}">
</Style>PlainView代码是在另一个项目中定义的。
发布于 2012-02-08 19:45:57
我不确定我是否正确理解了你的问题(或者即使你仍然有这个问题),所以我告诉你我的方法,我想我需要一些类似的东西:
中。
首先,确保在所有需要的项目中都有所有必需的引用。
存储密钥的类:
public class CoreResourceKeys
{
public static readonly string BrushMyBrush = "MyBrush";
public static ComponentResourceKey Brush_MyBrush
{
get
{
return new ComponentResourceKey(typeof(CoreResourceKeys), CoreResourceKeys.BrushMyBrush);
}
}
}我的主题文件看起来像这样:
<ResourceDictionary xmlns=[...]
xmlns:resources="clr-namespace:AssemblyThatStoresTheKeys;assembly=CoreResourceKeys">
<SolidColorBrush x:Key="{ComponentResourceKey
TypeInTargetAssembly={x:Type resources:CoreResourceKeys},
ResourceId={x:Static resources:CoreResourceKeys.BrushMyBrush}}"
Color="DarkMagenta"/>
</ResourceDictionary>而我想要使用画笔的控件/页面看起来像这样:
<UserControl x:Class=[...]
xmlns:resources="clr-namespace:AssemblyThatStoresTheKeys;assembly=CoreResourceKeys">
<TextBlock Background="{DynamicResource {x:Static resources:CoreResourceKeys.Brush_MyBrush}}" Text="The Shire"/>
那篇博文对我帮助很大:MSDN Support Forum - Loading Styles from My Assembly
我不确定这对你有帮助。如果没有,请尝试更详细地描述您的问题。
https://stackoverflow.com/questions/8838543
复制相似问题