首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MouseOver ContentPresenter XAML风格

MouseOver ContentPresenter XAML风格
EN

Stack Overflow用户
提问于 2015-07-31 10:38:18
回答 1查看 844关注 0票数 0

我需要改变鼠标的颜色/点点的内容演示者,但我的风格不起作用。

谁来帮我?

谢谢

代码语言:javascript
复制
<Style x:Key="Test" TargetType="ContentPresenter">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal"/>
                        <VisualState x:Name="PointerOver">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ColorTest}"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Pressed">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ColorTest}"/>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Disabled"/>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
            </Style>
EN

回答 1

Stack Overflow用户

发布于 2015-10-25 20:18:56

我认为这是不可能的。可视化状态由特定控件发布,ContentPresenter表示任何类型的控件或任意复杂的元素树。

您可以使用控件样式和模板中的子节来了解哪个Visual对每个控件有效,但正如您所看到的,这些都是特定于所讨论的控件的,而且并不总是支持每个状态。

您的样式可以修改为使用触发器(如<Trigger Property="IsMouseOver" Value="True"> ),但是您只能为ContentPresenter的属性提供设置器,而Foreground不是其中之一。

更新

但是,由于TextBlock.Foreground是附加属性,因此可以使触发器解决方案在特定示例中工作,并包含复杂的控件内容。但请注意,这并不适用于所有属性。

代码语言:javascript
复制
<Grid>
    <Grid.Resources>
        <ControlTemplate TargetType="Button" x:Key="ButtonControlTemplate">
            <ContentPresenter />
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="TextBlock.Foreground" Value="Red" />
                </Trigger>
                <Trigger Property="IsPressed" Value="True">
                    <Setter Property="TextBlock.Foreground" Value="Blue" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Grid.Resources>
    <Button Template="{StaticResource ButtonControlTemplate}" Content="Test" />
</Grid>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31744145

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档