.csファイルのないスタイルxamlがあります
以下に私のコードの一部を見つけることができます。そこにあなたは見つけることができますTextBlock
。ユーザーがアクション(ホバー、クリックなど)を実行したときに、そこでフォントの色を変更したいと思います。ご覧のとおり、のイベントを処理するVisualStateManagerがありますCombobox
。Visual State Managerで前景を上書きすることはできますか(たとえば、「クリック」の場合は赤、「ホバー」の場合は青)?
私は自分の問題の解決策を見つけるために多くの時間を費やしましたが、解決策はありません...
誰かが私を助けることができますか?解決策は、私のコントロールからのすべてのスタイルを保持する実装されたxamlファイルにのみあることに注意してください。
<Border x:Name="ContentPresenterBorder"
BorderBrush="Blue">
<Grid>
<ToggleButton x:Name="DropDownToggle"
HorizontalAlignment="Stretch"
Margin="0"
Style="{StaticResource comboToggleStyle}"
VerticalAlignment="Stretch"
BorderThickness="{TemplateBinding BorderThickness}"
HorizontalContentAlignment="Right"
Background="White"
BorderBrush="{x:Null}">
</ToggleButton>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="TextTextBlock"
Text="{TemplateBinding Tag}"
FontWeight="Bold"
Foreground="White"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Padding="{TemplateBinding Padding}"
Effect="{StaticResource MenuDropShadowEffect}"
IsHitTestVisible="False">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<ei:ChangePropertyAction PropertyName="Foreground">
<ei:ChangePropertyAction.Value>
<SolidColorBrush Color="#FF04A925" />
</ei:ChangePropertyAction.Value>
</ei:ChangePropertyAction>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<ei:ChangePropertyAction PropertyName="Foreground">
<ei:ChangePropertyAction.Value>
<SolidColorBrush Color="Black"/>
</ei:ChangePropertyAction.Value>
</ei:ChangePropertyAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
<Path x:Name="BtnArrow"
Stretch="Uniform"
Height="4"
HorizontalAlignment="Right"
Margin="0,0,6,0"
Width="8"
Fill="White"
Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z "
Effect="{StaticResource MenuDropShadowEffect}"
IsHitTestVisible="False">
</Path>
</StackPanel>
<ContentPresenter x:Name="ContentPresenter"
Visibility="Collapsed" />
</Grid>
</Border>
<Rectangle x:Name="DisabledVisualElement"
Fill="White"
RadiusX="3"
RadiusY="3"
IsHitTestVisible="false"
Opacity="0" />
<Rectangle x:Name="FocusVisualElement"
Stroke="{x:Null}"
StrokeThickness="1"
RadiusX="2"
RadiusY="2"
Margin="1"
IsHitTestVisible="false"
Opacity="0"
Fill="{x:Null}" />
<Border x:Name="ValidationErrorElement"
Visibility="Collapsed"
BorderBrush="#FFDB000C"
BorderThickness="1"
CornerRadius="1">
<ToolTipService.ToolTip>
<ToolTip x:Name="validationTooltip"
DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Template="{StaticResource ValidationToolTipTemplate}"
Placement="Right"
PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<ToolTip.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip"
Storyboard.TargetProperty="IsHitTestVisible">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<System:Boolean>true</System:Boolean>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ToolTip.Triggers>
</ToolTip>
</ToolTipService.ToolTip>
<Grid Height="12"
HorizontalAlignment="Right"
Margin="1,-4,-4,0"
VerticalAlignment="Top"
Width="12"
Background="Transparent">
</Grid>
</Border>
<Popup x:Name="Popup"
Margin="0,1,0,0">
<Border x:Name="PopupBorder"
Height="Auto"
HorizontalAlignment="Stretch"
CornerRadius="3"
BorderBrush="#FFC1C1C1"
BorderThickness="0,0,1,1">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#FFFFFFFF"
Offset="0" />
<GradientStop Color="#FFFEFEFE"
Offset="1" />
</LinearGradientBrush>
</Border.Background>
<ScrollViewer x:Name="ScrollViewer"
BorderThickness="0"
Padding="1">
<ItemsPresenter />
</ScrollViewer>
</Border>
</Popup>
<ContentControl x:Name="HeaderText" Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center" HorizontalAlignment="Center" >
<ContentPresenter x:Name="contentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<ContentPresenter.Effect>
<DropShadowEffect BlurRadius="0"
Color="#FF666666"
Direction="90"
ShadowDepth="1"/>
</ContentPresenter.Effect>
</ContentPresenter>
</ContentControl>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
</Storyboard>
</VisualState>
<VisualState x:Name="MouseOver" >
<!--<Storyboard>
<ColorAnimation
Storyboard.TargetName="HeaderText"
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"
Duration="0" To="#FF000000"/>
</Storyboard>-->
<Storyboard>
<ColorAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="Content"
Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)">
<SplineColorKeyFrame KeyTime="00:00:00.4000000" Value="#FFFF0000"/>
</ColorAnimationUsingKeyFrames>-->
<!--<ColorAnimation
BeginTime="00:00:00"
Duration="00:00:00.0010000"
From="#FFFFFFFF" To="#FF000000"
Storyboard.TargetName="Content"
Storyboard.TargetProperty="(UIElement.Foreground).Color"
/>-->
<ColorAnimation
BeginTime="00:00:00"
Duration="00:00:00.0010000"
From="#FFFFFFFF" To="#FF000000"
Storyboard.TargetName="Content"
Storyboard.TargetProperty="(TextBlock.Foreground).Color"
/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="DisabledVisualElement"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00"
Value=".55" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00"
Value="1" />
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="HeaderText"
Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)">
<SplineColorKeyFrame KeyTime="00:00:00.4000000" Value="#FFFF0000"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unfocused" />
<VisualState x:Name="FocusedDropDown">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TextTextBlock"
Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.Direction)">
<EasingDoubleKeyFrame KeyTime="00:00:00"
Value="-90" />
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TextTextBlock"
Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.Color)">
<EasingColorKeyFrame KeyTime="00:00:00"
Value="#FF333333" />
</ColorAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TextTextBlock"
Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.ShadowDepth)">
<EasingDoubleKeyFrame KeyTime="00:00:00"
Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TextTextBlock"
Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.BlurRadius)">
<EasingDoubleKeyFrame KeyTime="00:00:00"
Value="2" />
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Duration="00:00:00"
Storyboard.TargetName="PopupBorder"
Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<!--<ColorAnimation
BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="Content"
Storyboard.TargetProperty="(UIElement.Foreground).(SolidColorBrush.Color)"
From="White" To="Black"
/>-->
<ColorAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="HeaderText"
Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)">
<SplineColorKeyFrame KeyTime="00:00:00.4000000" Value="#FFFF0000"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="ValidationStates">
<VisualState x:Name="Valid" />
<VisualState x:Name="InvalidUnfocused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement"
Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="InvalidFocused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement"
Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip"
Storyboard.TargetProperty="IsOpen">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<System:Boolean>True</System:Boolean>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>