2014-08-31 58 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文件來完成。