Style
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}"> <Setter Property="SnapsToDevicePixels" Value="True"/> <Setter Property="OverridesDefaultStyle" Value="True"/> <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="MinWidth" Value="120"/> <Setter Property="MinHeight" Value="20"/> <Setter Property="AllowDrop" Value="true"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TextBoxBase}"> <Border x:Name="Border" BorderThickness="1" CornerRadius="2" Padding="0"> <Border.BorderBrush> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1"> <GradientStop Color="#888888" Offset="0" /> <GradientStop Color="#AAAAAA" Offset=".2" /> </LinearGradientBrush> </Border.BorderBrush> <ScrollViewer x:Name="PART_ContentHost" Margin="0"> <ScrollViewer.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="WhiteSmoke"/> <GradientStop Offset="1" Color="LightGray"/> </LinearGradientBrush> </ScrollViewer.Background> </ScrollViewer> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter TargetName="Border" Property="Background" Value="#EEEEEE"/> <Setter TargetName="Border" Property="BorderBrush" Value="#EEEEEE"/> <Setter Property="Foreground" Value="#888888"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
UpdateSourceTrigger
NumberTextbox
- 使用NubmberTextboxBehavior
- 将TextBox的binding属性中Delay设置为1000
WaterMark/HintText/PlaceHoder
参考
WPF validation rule preventing decimal entry in textbox?
Set WPF Binding.StringFormat Property on TextBox via Style
时间: 2024-10-14 16:43:55