2014-08-31 57 views
1

我每次启动Windows应用程序new Application().Run(new MainWindow())我的WPF应用程序 - 所以我没有一个的App.xaml如何在UserControl中从外部窗口继承资源?

我有一个主窗口,其中包含每ContentControl中

<Window ..> 
    <Window.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="..." /> 
       <!-- ... --> 
      <converter:BooleanToIntConverter x:Key="BooleanToIntConverter" /> 
     </ResourceDictionary> 
    </Window.Resources> 

    <ContentControl Grid.Column="0" Content="{Binding MyUserControl}" /> 
</Window> 

如何使用任何用户控件我可以从MainWindow继承资源到MainControlow中的UserControls吗?

回答

1

您可以通过访问设置资源ApplicationResourcesResourceDictionary

Application app = new Application(); 
app.Resources["MySharedResource"] = ...; 
app.Resources["MyOtherSharedResource"] = ...; 
app.Run(new MainWindow()); 

这正是与App.xaml文件来完成。