私はWPFアプリケーションであるc#プロジェクトを持っていますが、今はdllとしてビルドしたいと考えています。私はこれまで、プロジェクトからapp.xamlを削除し、そのビルドタイプをdllに設定しました。コードからアプリケーションリソースを設定する
問題は、app.xamlにアプリケーション変数をインスタンス化するためのxamlが含まれていることです。これをラウンドするには、これらのアプリケーション変数を呼び出される最初のxamlウィンドウ内からプログラムで設定しようとしています。
私はコードでエミュレートしようとしているXAMLは次のとおりです。
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Shared.xaml"/>
<ResourceDictionary Source="Resources/Styles/ToolBar.xaml"/>
<ResourceDictionary Source="Resources/Styles/GroupBox.xaml"/>
<ResourceDictionary Source="Resources/Styles/ZoomBox.xaml"/>
<ResourceDictionary Source="Resources/Styles/ScrollBar.xaml"/>
<ResourceDictionary Source="Resources/Styles/Expander.xaml"/>
<ResourceDictionary Source="Resources/ApplicationToolbar.xaml"/>
<ResourceDictionary Source="Resources/DesignerItem.xaml"/>
<ResourceDictionary Source="Resources/Styles/ToolboxItem.xaml"/>
<ResourceDictionary Source="Resources/Styles/Toolbox.xaml"/>
<ResourceDictionary Source="Resources/Connection.xaml"/>
<ResourceDictionary Source="Resources/Slider.xaml"/>
<ResourceDictionary Source="Resources/ScrollViewer.xaml"/>
<ResourceDictionary Source="Resources/StatusBar.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
これは私が持っているコードです:
ResourceDictionary myResourceDictionary = new ResourceDictionary();
myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\Shared.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\ToolBar.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\GroupBox.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\ZoomBox.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\ScrollBar.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\Expander.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\ApplicationToolbar.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\DesignerItem.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\ToolboxItem.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\Toolbox.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\Connection.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\Slider.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\ScrollViewer.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("C:\\Resources\\StatusBar.xaml");
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
は、この作業は必要がありますか?
Shared.xamlで宣言されているリソースが参照されているにもかかわらず、Toolbar.xamlがそのリソースを参照していて、取得できず、次のエラーが表示されるという問題が発生しました。ここで
Cannot find resource named 'ToolbarSelectedBackgroundBrush'. Resource names are case sensitive.
リソースがshared.xaml
<LinearGradientBrush x:Key="ToolbarSelectedBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFFEE3" Offset="0.0"/>
<GradientStop Color="#FFE797" Offset="0.4"/>
<GradientStop Color="#FFD750" Offset="0.4"/>
<GradientStop Color="#FFE796" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
をしてdelcaredされている場合、ここでその質問が、思考のエッセイのための
<Setter TargetName="Border" Property="Background" Value="{StaticResource ToolbarSelectedBackgroundBrush}" />
申し訳toolbar.xamlで参照のWHERE私はできるだけ多くの情報を提供しています。あなたが何か他のものが必要な場合は教えてください。
、BECでなければなりませんMy.Wpf.Component
を置く必要がありますあなたはもはや 'App.xaml'を使用せず、回避策としてコードを書いています。 * https://stackoverflow.com/questions/4441227/wpf-class-library-with-resource-dictionary/4441500#4441500のままで、あなたは* App *が引き続き 'App.xaml'を使うことができます。次に、呼び出し側のDLLはhttps://stackoverflow.com/a/26890426/1429390のように 'App'をインスタンス化します。相対的なURIのおかげで、すべてのリソースが動作し、時間と実行時間を設計できます。 –