最后项目中美工给出了一套设计方案,需要修改Textbox控件的样式,于是修改一下默认的样式和模板
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converter="clr-namespace:IVF.Converter">
<!--for TextboxDictionary.xaml Border CornerRadius-->
<converter:HeightToCornerConverter x:Key="HeightToCornerConverter" />
<SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
<SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
<SolidColorBrush x:Key="TextBox.Focus.Border" Color="#7278FB"/>
<Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"

这篇博客详细介绍了如何使用XAML修改TextBox控件的样式和模板,包括设置边框颜色、鼠标悬停和焦点时的效果,并通过HeightToCornerConverter实现边框圆角与控件高度的自适应。此外,还展示了ScrollViewer的自定义模板,以及在不同状态下的触发器行为。最终实现了美观且功能完整的输入框设计。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



