2012-12-13 30 views
0

我正在使用从ViewBase派生的自定义视图的Xaml文件,并且我想访问位于不同程序集中的DynamicResource。我已经看到,有可能使用类似:如何从ViewBase中的其他程序集访问动态资源

<Application.Resources> 
    <ResourceDictionary 
    Source="/mylib;Resources/MyStyleDictionary.xaml" /> 
</Application.Resources> 

但是我处理XAML文件看起来是这样的:

<myLib:ViewBase> 
    <Grid> 
     <Button> 
      Style="{DynamicResource MyButtonStyle}" // I want this style to come from a different assembly 
     </Button> 
    </Grid> 
</myLib:ViewBase> 

我怎样才能做到这一点?

回答

1

了解动态和静态资源之间的区别很重要。 What's the difference between StaticResource and DynamicResource in WPF?

但是,为了回答这个问题:

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="/SomeOtherAssembly;Resources/SomeOtherDictionaryWithMyButtonStyleKey.xaml" /> 
      <ResourceDictionary Source="/mylib;Resources/MyStyleDictionary.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

资源被动态引用,在MyStyleDictionary.xaml合并应后再进行合并SomeOtherDictionaryWithMyButtonStyleKey.xaml。

+0

谢谢你,但这个Application.Resources放在哪里?我正在使用ViewBase xaml,并且在这个项目 –

+0

中没有App.xaml,无论资源级别是否合理。资源是FrameworkElement上的一个属性。 – user1834059

相关问题