wpf - 使用 VisualStateManager 在 MouseOver 上展开 TextBox
问题描述
我在 RecourceDictionary 中定义我自己的 ControlTemplate。我在定义 VisualStateManager 时遇到问题,这是我的代码:
<Style x:Key="SchedulerTextBox" TargetType="TextBox">
<Setter Property="SnapsToDevicePixels"
Value="True" />
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="KeyboardNavigation.TabNavigation"
Value="None" />
<Setter Property="AllowDrop"
Value="True" />
<Setter Property="Foreground"
Value="{StaticResource TextForeground}" />
<Setter Property="Background"
Value="{StaticResource TextBoxBackground}" />
<Setter Property="Width"
Value="50" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox" >
<Border Background="{TemplateBinding Background}"
BorderBrush="Red"
BorderThickness="1"
CornerRadius="5"
x:Name="Border"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}">
<ScrollViewer Margin="0" x:Name="PART_ContentHost" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates" >
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Duration="0:0:2"
By="100" From="{TemplateBinding Width}"
Storyboard.TargetProperty="Width" />
<DoubleAnimation Duration="0:0:2"
By="100" From="{TemplateBinding Height}"
Storyboard.TargetProperty="Height" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我不知道为什么,但文本框显示如下: On Hover
没有鼠标悬停在文本框上看起来像这样: WithoutHover
有谁知道为什么文本框部分显示,我该如何解决这个问题?谢谢你的帮助!
解决方案
推荐阅读
- google-cloud-endpoints - Google Cloud Endpoints - 无法解析开放 API 错误
- c# - 在 WinUI3 中以编程方式关闭 MessageDialog
- php - 使用 Delta 和规范化迁移到 PHPUnit9 equalTo
- swift - 什么时候显示“您想将此密码保存在您的 iCloud 钥匙串中”的提示吗?
- python - 在Python中采样大于p的n个随机素数的最快方法?
- ios - 无法理解符号化的崩溃报告
- python - 如何让 DJANGO 在网页上获取我的 dht11 或 mlx90614 红外读取传感器值?
- python - Python:如何创建孩子必须使用的方法
- java - 如何每小时调用一次这种改造方法?
- python - Django 表单 IntegerField 值验证