私はすでに尋ねようとしましたが、おそらく十分な情報を提供していませんでした. 独自の WPF テーマを作成しようとしています。このスタイルを作成するまでは、すべて問題ありませんでした。
<Style TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_ContentHost">
<EasingDoubleKeyFrame KeyTime="0" Value="0.5"/>
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="Background">
<EasingColorKeyFrame KeyTime="0" Value="Red"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="Background">
<EasingColorKeyFrame KeyTime="0" Value="Yellow"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="ReadOnly"/>
<VisualState x:Name="MouseOver"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="Background" Fill="{StaticResource OniiControlBackgroundBrush}" Stroke="{StaticResource OniiNormalBrush}" RadiusX="2" RadiusY="2"/>
<ScrollViewer x:Name="PART_ContentHost" Margin="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" FontFamily="{TemplateBinding FontFamily}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
</Style>
TextBox が無効の場合、TextBox Background と BorderBrush の色を変更することになっています。
色は同じ ResourceDictionary で定義されています
<Color x:Key="MainColor">#FF595959</Color>
<Color x:Key="OniiControlBackgroundColor">#FF333333</Color>
<SolidColorBrush x:Key="OniiNormalBrush" Color="{StaticResource MainColor}"/>
<SolidColorBrush x:Key="OniiControlBackgroundBrush" Color="{StaticResource OniiControlBackgroundColor}" />
そして、私が知らない本当の問題は何ですか。私が知っていること:
1/ "TextBox を無効にすると、OniiControlBackgroundBrush を使用するすべての色が赤色に変わります"
- OniiControlBackgroundBrush は、他のスタイルで StaticResource として参照されます。
2/「これらの色を切り替えると、OniiControlBackgroundBrush のみが変更されますが、今回は黄色に変更されます」
<Rectangle x:Name="Background" Fill="{StaticResource OniiNormalBrush}" Stroke="{StaticResource OniiControlBackgroundBrush}" RadiusX="2" RadiusY="2"/>
- OniiNormalBrush は、他のスタイルでも StaticResource として参照されます。
3/ 「すべてが 1 つのリソース ディクショナリで定義されている」
<Application.Resources>
<ResourceDictionary Source="Theme/OniiResourceDictionary.xaml">
</ResourceDictionary>
</Application.Resources>
4/ 「カスタム スタイルの少ない小さなソリューションでこの問題を再現しようとしましたが、成功しませんでした」
同じ TextBox スタイルを使用しました。
<TextBox Height="32" HorizontalAlignment="Left" Margin="38,51,0,0" Name="textBox1" VerticalAlignment="Top" Width="215" /> <CheckBox Content="Enabled" Height="16" HorizontalAlignment="Left" Margin="259,51,0,0" Name="checkBox1" VerticalAlignment="Top" Checked="checkBox1_Checked" Unchecked="checkBox1_Unchecked" /> <Border Height="148" HorizontalAlignment="Left" Margin="254,126,0,0" Name="border1" VerticalAlignment="Top" Width="98" /> <Rectangle Fill="{StaticResource OniiNormalBrush}" StrokeThickness="20" Stroke="{StaticResource OniiControlBackgroundBrush}" Height="148" HorizontalAlignment="Left" Margin="358,126,0,0" Name="rectangle5" VerticalAlignment="Top" Width="99" />
Textbox は CheckBox によって無効化および有効化され、Border は両方の色を StaticResources としてカスタム スタイルを使用します
5/「元のソリューションに次のコードを追加すると、問題が消えます」
<Rectangle Height="71" HorizontalAlignment="Left" Margin="130,131,0,0" Name="rectangle2" StrokeThickness="20" Stroke="{StaticResource OniiControlBackgroundBrush}" Fill="{StaticResource OniiNormalBrush}" VerticalAlignment="Top" Width="98" />
私は本当に何かを逃していますか?それとも私は本当に愚かですか?とにかく、あなたの助けをいただければ幸いです。私は本当に迷っています。最後に x:Shared="false" を使用したくないのは、主に OniiNormalBrush の変更に問題がないことがわかっているためです。ありがとうございました。