質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

.NET Framework

.NET Framework は、Microsoft Windowsのオペレーティングシステムのために開発されたソフトウェア開発環境/実行環境です。多くのプログラミング言語をサポートしています。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

Q&A

解決済

2回答

524閲覧

ResourceDictionaryWPFでのAeroテーマをデフォルトスタイルにしたい

TomeSq

総合スコア10

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

.NET Framework

.NET Framework は、Microsoft Windowsのオペレーティングシステムのために開発されたソフトウェア開発環境/実行環境です。多くのプログラミング言語をサポートしています。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

0グッド

1クリップ

投稿2018/10/29 00:40

編集2018/10/30 00:02

開発環境

  • VS2017
  • .net framework 4.7.1
  • c#

モジュール構成

AeroTest.exe - MainWindow.xamlを実装したモジュール
Resources.dll - ResourceDictionaryでstyleを定義したDLL

Resources.dll内で別途スタイルを定義してAeroテーマをボタンなどのデフォルトテーマにしたく指定しているのですが反映されません。
Resources.dll内でAeroテーマをResourceDictionary.MergedDictionariesで追加しても反映されない仕様なのでしょうか。
ちなみにApp.xaml内で直接AeroテーマをMergedDictionariesに追加する分にはうまくいきます。

アセンブリ名:Resources
ソース名:styles.xaml

c#

1<ResourceDictionary 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 4 5 <ResourceDictionary.MergedDictionaries> 6 <ResourceDictionary Source="/PresentationFramework.AeroLite;component/themes/aerolite.normalcolor.xaml" /> 7 </ResourceDictionary.MergedDictionaries> 8 9 10 <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> 11 <Setter Property="Margin" Value="5,5,5,5"/> 12 <Setter Property="VerticalAlignment" Value="Center"/> 13 <Setter Property="VerticalContentAlignment" Value="Center"/> 14 <Setter Property="Height" Value="25"/> 15 </Style> 16</ResourceDictionary>

アセンブリ名:AeroTest
ソース名:App.xaml

c#

1<Application x:Class="AeroTest.App" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:local="clr-namespace:AeroTest" 5 StartupUri="MainWindow.xaml"> 6 <Application.Resources> 7 <ResourceDictionary> 8 <ResourceDictionary.MergedDictionaries> 9 <ResourceDictionary Source="pack://application:,,,/Resources;component/styles.xaml"/> 10 </ResourceDictionary.MergedDictionaries> 11 </ResourceDictionary> 12 </Application.Resources> 13</Application>

アセンブリ名:AeroTest
ソース名:MainWindow.xaml

c#

1<Window x:Class="AeroTest.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:AeroTest" 7 mc:Ignorable="d" 8 Title="MainWindow" Height="450" Width="800"> 9 <StackPanel> 10 <Button Content="ボタン1"/> 11 <Button Content="ボタン2"/> 12 </StackPanel> 13</Window>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hihijiji

2018/10/29 03:42

カスタムコントロールはResourceDictionaryの間違いでしょうか?カスタムコントロールで定義したリソースは原則カスタムコントロール内だけで使います。いずれにしても呼ばないと使えません。
TomeSq

2018/10/29 06:14

ご指摘ありがとうございます。カスタムコントロールではなくResourceDictionaryが正しいので修正しました。
guest

回答2

0

ベストアンサー

ResourceDictionaryで別途スタイルを定義してAeroテーマをボタンなどのデフォルトテーマにしたく指定している

というのは、
ResourceDictionary.xaml
というファイルですよね?

これを適用するように指定している箇所が見当たらないのですが・・・

App.xamlの

<ResourceDictionary Source="pack://application:,,,/Styles;component/Generic.xaml"/>

<ResourceDictionary Source="ResourceDictionary.xaml"/>

にするとどうですか?


追記 2018/10/30 10:39

Resources.dllプロジェクトの方で、styles.xaml の

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> <Setter Property="Margin" Value="5,5,5,5"/> <Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Height" Value="25"/>
</Style>

を別のディクショナリ(例えば)Dictionary1.xamlファイルに切り出し、
styles.xaml側を

xaml

1<ResourceDictionary 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 4 5 <ResourceDictionary.MergedDictionaries> 6 <ResourceDictionary Source="Dictionary1.xaml" /> 7 <ResourceDictionary Source="/PresentationFramework.AeroLite;component/themes/aerolite.normalcolor.xaml" /> 8 </ResourceDictionary.MergedDictionaries> 9</ResourceDictionary>

こんな感じに書けば動きました。

動いてませんでした。
"Dictionary1.xaml"のスタイルが全く適用されていませでした。

どうしたものか(^_^;)


追記:2018/10/30 11:30

何度もすみません。
こちらのサイトに載っている方法でしたら、なんとか動いたようです。
http://tkatochin.hatenablog.com/entry/20080916/1221565841

xaml

1<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 3 4 <ResourceDictionary.MergedDictionaries> 5 <ResourceDictionary Source="/PresentationFramework.AeroLite;component/themes/aerolite.normalcolor.xaml" /> 6 7 <ResourceDictionary> 8 <Style x:Key="__Type_Button__" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> 9 <Setter Property="Margin" Value="5,5,5,5"/> 10 <Setter Property="VerticalAlignment" Value="Center"/> 11 <Setter Property="VerticalContentAlignment" Value="Center"/> 12 <Setter Property="Height" Value="25"/> 13 </Style> 14 15 </ResourceDictionary> 16 17 </ResourceDictionary.MergedDictionaries> 18 19 <Style TargetType="Button" BasedOn="{StaticResource __Type_Button__}"/> 20 21</ResourceDictionary>

Qiitaの記事にもThemeとStyleのマージという項目がありましたが、手元では反映されなかったので、なかなかこの辺の挙動はよくわからないです。
https://qiita.com/norimatsu_yusuke/items/3a7a22f0d852d99e18cc

投稿2018/10/29 07:50

編集2018/10/30 02:37
takabosoft

総合スコア8356

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

TomeSq

2018/10/30 00:04

質問の仕方と構成が分かりづらく大変申し訳ありません。 別モジュール内で```styles.xam```というソースにStyleを定義しております。
takabosoft

2018/10/30 00:31

Debug/binフォルダ内にPresentationFramework.AeroLite.dll(?)とResources.dllは両方配置されているんでしょうかね?
TomeSq

2018/10/30 02:30

はい。配置しています。
takabosoft

2018/10/30 02:46

回答欄へ11:30に追記したものをとりあえず試してみてください。たぶん動くには動くと思います。
TomeSq

2018/10/30 03:03

ありがとうございます。無事動作しました。 ResourceDictionary内で別名定義してそいつをデフォルトスタイルにするとは思いませんでした。
guest

0

回答まちがってたので消しました

投稿2018/10/29 13:08

編集2018/10/29 13:10
gaya-K

総合スコア449

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問