トップ回答者
ThemeをClassicにしても、Styleを使うとThemeがデフォルトに戻ってしまう。

質問
-
作業現場で用いるアプリケーションの外観を変えたくないので、クラシックなテーマを使うため、
<Application.Resources> <ResourceDictionary Source="/presentationframework.Classic;component/themes/classic.xaml" /> </Application.Resources>
としたところ、まずは上手くいきました。小生の作業環境Windows 7のテーマAeroに対して、このアプリケーションだけテーマがClassicになります。
次に、個々のコントロールで「注意状態」「通常状態」というような表示の切り替えをしたいので、下記のように個別にStyleを適用したところ、Styleで指定したプロパティーは指示通りに変更されるものの、テーマまでが変わってしまい元のテーマAeroに基づく表示になってしまいます。上記のテーマ設定を引き継ぎつつ、個別にStyleを適用するにはどう書けば良いのでしょうか?<Window x:Class="WpfStudyThemeClassic.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfStudyThemeClassic"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="300">
<Window.Resources>
<Style x:Key="Warning" TargetType="Button">
<Setter Property="Foreground" Value="Red"/>
</Style>
</Window.Resources>
<Grid>
<Button x:Name="_btn" Content="Button"
HorizontalAlignment="Left" VerticalAlignment="Top"
Height="50" Width="100"
Margin="90,50,0,0"
Style="{StaticResource Warning}"
/>
<Button x:Name="_btn2" Content="Button"
HorizontalAlignment="Left" VerticalAlignment="Top"
Height="50" Width="100"
Margin="90,130,0,0"
/>
</Grid>
</Window>実行状況は以下のとおり。
- 編集済み 外池 2019年11月26日 0:04