单独汇编中的资源字典智能感知

JLa*_*ord 9 .net vb.net wpf xaml visual-studio-2015

我在vs2015中有两个程序集的解决方案.其中一个是WPF应用程序,另一个是WPF类库.

在我的类库项目根我有一个ResourceDictionary调用Directory.xaml- 这有一些样式,一些画笔和一些字符串等.

使用:

<ResourceDictionary Source="pack://application:,,,/Resources;component/Directory.xaml"/>
Run Code Online (Sandbox Code Playgroud)

我可以成功使用这些资源,但是我打算在未来的项目中使用已编译的类库(dll),问题是,除非我导入项目和引用,而不仅仅是引用dll,我没有任何intellisense支持.

有任何想法吗?

小智 1

我希望有人能提出更好的答案,但我决定的解决方法是使用库 dll 中的类,其键定义为 const 字符串,使用字典中定义的字符串,然后使用应用程序中定义的字符串,我可以在按键上获得智能感知。

在库 dll 中,创建一个定义资源键的类:

public class KeyDefinitions {
  public const string Key1 = "key1";
  public const string Key2 = "key2";
}
Run Code Online (Sandbox Code Playgroud)

另外,在库 dll 的资源字典中,使用这些键(遗憾的是,我没有在库的资源 xaml 文件中获取 Intellisense 来检测 KeyDefinitions 的成员):

<BitmapImage x:Key="{x:Static local:KeyDefinitions.Key1}" UriSource="../Images/Img1.bmp"/>
<BitmapImage x:Key="{x:Static local:KeyDefinitions.Key2}" UriSource="../Images/Img2.bmp"/>
Run Code Online (Sandbox Code Playgroud)

然后,在应用程序的 xaml 中,您可以引用 KeyDefinitions 类中的键并获取键的智能感知和编译时检查:

<Image Source="{DynamicResource ResourceKey={x:Static myLibraryNamespace:KeyDefinitions.Key1}}" />
<Image Source="{DynamicResource ResourceKey={x:Static myLibraryNamespace:KeyDefinitions.Key2}}" />
Run Code Online (Sandbox Code Playgroud)

当然,这假设您可以控制 Library dll!