Bind TextBox on Enter-key press

You can make yourself a pure XAML approach by creating an attached behaviour. Something like this: public static class InputBindingsManager { public static readonly DependencyProperty UpdatePropertySourceWhenEnterPressedProperty = DependencyProperty.RegisterAttached( “UpdatePropertySourceWhenEnterPressed”, typeof(DependencyProperty), typeof(InputBindingsManager), new PropertyMetadata(null, OnUpdatePropertySourceWhenEnterPressedPropertyChanged)); static InputBindingsManager() { } public static void SetUpdatePropertySourceWhenEnterPressed(DependencyObject dp, DependencyProperty value) { dp.SetValue(UpdatePropertySourceWhenEnterPressedProperty, value); } public static DependencyProperty GetUpdatePropertySourceWhenEnterPressed(DependencyObject dp) { … Read more

How can I add a hint text to WPF textbox?

You can accomplish this much more easily with a VisualBrush and some triggers in a Style: <TextBox> <TextBox.Style> <Style TargetType=”TextBox” xmlns:sys=”clr-namespace:System;assembly=mscorlib”> <Style.Resources> <VisualBrush x:Key=”CueBannerBrush” AlignmentX=”Left” AlignmentY=”Center” Stretch=”None”> <VisualBrush.Visual> <Label Content=”Search” Foreground=”LightGray” /> </VisualBrush.Visual> </VisualBrush> </Style.Resources> <Style.Triggers> <Trigger Property=”Text” Value=”{x:Static sys:String.Empty}”> <Setter Property=”Background” Value=”{StaticResource CueBannerBrush}” /> </Trigger> <Trigger Property=”Text” Value=”{x:Null}”> <Setter Property=”Background” Value=”{StaticResource CueBannerBrush}” /> </Trigger> … Read more

Limit number of characters allowed in form input text field

maxlength: The maximum number of characters that will be accepted as input. This can be greater that specified by SIZE , in which case the field will scroll appropriately. The default is unlimited. <input type=”text” maxlength=”2″ id=”sessionNo” name=”sessionNum” onkeypress=”return isNumberKey(event)” /> However, this may or may not be affected by your handler. You may need … Read more