###前提・実現したいこと
App.xamlにスタイル設定がしたい
###発生している問題・エラーメッセージ
App.xamlにスタイルを設定すると意図せぬコントロールのスタイルまで変更されてしまう
###該当のソースコード
・App.xaml
C#
1<Application x:Class="Test.App" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 StartupUri="MainWindow.xaml"> 5 <Application.Resources> 6 <Style TargetType="{x:Type Button}"> 7 <Setter Property="Foreground" Value="Blue"/> 8 </Style> 9 10 <Style TargetType="{x:Type TextBlock}"> 11 <Setter Property="FontSize" Value="50"/> 12 <Setter Property="Foreground" Value="Red"/> 13 </Style> 14 </Application.Resources> 15</Application>
・MainWindow.xaml
C#
1<Window x:Class="Test.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 Title="MainWindow" Height="350" Width="525"> 5 <StackPanel> 6 <Button Content="サンプル" Width="100" Height="100" /> 7 <TextBlock Text="サンプル" Width="200" Height="100"/> 8 </StackPanel> 9</Window>
・MainWindow.cs
C#
1using System.Windows; 2 3namespace Test 4{ 5 /// <summary> 6 /// MainWindow.xaml の相互作用ロジック 7 /// </summary> 8 public partial class MainWindow : Window 9 { 10 public MainWindow() 11 { 12 InitializeComponent(); 13 } 14 } 15}
###試したこと
上記の場合にデザイナではボタンの色は「青」テキストブロックの色は「赤」になっています。
それが実行するとボタンの色が「赤」に変わります。またフォントサイズも50に変わります。
App.xamlのスタイルをMainWindow.xamlに持って行くと、このような現象は起こりません。
下記のように記述しても同現象です。
C#
1<Style TargetType="TextBlock"> 2 <Setter Property="FontSize" Value="50"/> 3 <Setter Property="Foreground" Value="Red"/> 4</Style>
そもそもApp.xamlにこのような記述のしかた自体、NGなのでしょうか?
よろしくお願いします。
###補足情報(言語/FW/ツール等のバージョンなど)
C#
VS2010 Pro
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/05/20 10:04