xaml - 如何在悬停时更改文本框标题颜色?
问题描述
我有以下内容:
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FontSize="12" Header="Name" >
<TextBox.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="Red" />
</DataTemplate>
</TextBox.HeaderTemplate>
有没有办法通过 DataTemplate 或 Xaml 行为来改变前景?
解决方案
您可以使用XamlBehaviors
.
在 Xaml 中添加 NugetMicrosoft.Xaml.Behaviors.Uwp.Managed
和引用。
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
处理PointerEntered
和PointerExited
事件TextBlock
。
<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>
推荐阅读
- javascript - 在 jQuery 的特定页面上加载和初始化多个 JS 插件
- pandas - 从另一个数据帧的切片重新分配熊猫列
- bash - CAT 和 tr 的 For 循环问题
- ruby - 有没有办法将鞋子 Ruby 应用程序打包到 APK 中?
- javascript - Twitch API 用户电子邮件未定义,没有与帐户关联的电子邮件?
- javascript - Vue-chart.js :获取部分数据;图表显示不好
- reactjs - React 使用 Redux 更新状态但不更新组件
- google-maps - phonegap build 未显示地图指针
- node.js - 接下来使用nodejs express
- javascript - 使用 TypeScript 泛型定义 Factory 方法的返回类型