C# 仅在Style.xaml中将文本块前景从ComboBox更改为Event fire

C# 仅在Style.xaml中将文本块前景从ComboBox更改为Event fire,c#,wpf-controls,C#,Wpf Controls,我有一个没有.cs文件的样式xaml 下面你可以找到我代码的一部分。您可以在那里找到文本块。我想在用户执行操作(悬停、单击等)时更改fontcolor。如您所见,VisualStateManager负责处理组合框的事件。是否可以在可视状态管理器中覆盖前景(例如:如果“单击”,则为红色,如果“悬停”,则为蓝色) 我已经花了很多时间为我的问题找到解决方案,但是没有解决方案 有人能帮我吗?注意,该解决方案仅在一个xaml文件中实现,该文件包含我控件中的所有样式 <Border x:Name="C

我有一个没有.cs文件的样式xaml

下面你可以找到我代码的一部分。您可以在那里找到
文本块
。我想在用户执行操作(悬停、单击等)时更改fontcolor。如您所见,VisualStateManager负责处理组合框的事件。是否可以在可视状态管理器中覆盖前景(例如:如果“单击”,则为红色,如果“悬停”,则为蓝色)

我已经花了很多时间为我的问题找到解决方案,但是没有解决方案

有人能帮我吗?注意,该解决方案仅在一个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>

真的
-->
看得见的
看得见的
看得见的
真的
用于鼠标悬停的


点击鼠标,大家好。。我可以自己解决! 错误是:

故事板。TargetName=“内容”。。。当然应该是指“文本块”。。。。 希望对其他人也有帮助