微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在悬停时更改文本框标题颜色?

如何解决如何在悬停时更改文本框标题颜色?

我有以下几点:

<TextBox HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" FontSize="12" Header="Name" >
    <TextBox.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" Foreground="Red" />
        </DataTemplate>
</TextBox.HeaderTemplate>

有没有办法通过 DataTemplate 或 Xaml 行为来改变前景?

解决方法

您可以使用 XamlBehaviors

在 Xaml 中添加 Nuget Microsoft.Xaml.Behaviors.Uwp.Managed 和引用。

 xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
 xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"

处理 PointerEntered 上的 PointerExitedTextBlock 事件。

<TextBox HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" FontSize="12" Header="Name" >
    <TextBox.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" Foreground="Red">
                <Interactivity:Interaction.Behaviors>
                    <Core:EventTriggerBehavior EventName="PointerEntered">
                        <Core:ChangePropertyAction PropertyName="Foreground">
                            <Core:ChangePropertyAction.Value>
                                <SolidColorBrush Color="Blue" />
                            </Core:ChangePropertyAction.Value>
                        </Core:ChangePropertyAction>
                    </Core:EventTriggerBehavior>
                    <Core:EventTriggerBehavior EventName="PointerExited">
                        <Core:ChangePropertyAction PropertyName="Foreground">
                            <Core:ChangePropertyAction.Value>
                                <SolidColorBrush Color="Red" />
                            </Core:ChangePropertyAction.Value>
                        </Core:ChangePropertyAction>
                    </Core:EventTriggerBehavior>
                </Interactivity:Interaction.Behaviors>
            </TextBlock>
        </DataTemplate>
    </TextBox.HeaderTemplate>
</TextBox>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。