How can I dynamically change auto complete entries in a C# combobox or textbox?

I had the same problem, and found an extremely simple workaround. As everybody else here, I couldn’t find any means to control de behaviour of the component, so I had to accept it. The natural behaviour is: you can’t dynamically populate the list every time the user types into the text box. You have to … Read more

WPF MVVM Focus Field on Load

If it makes you feel better (it makes me feel better) you can do this in Xaml using an attached property: http://msdn.microsoft.com/en-us/library/system.windows.input.focusmanager.focusedelement.aspx Anything you can do in codebehind you can do in Xaml if you know the tricks. Fortunately, you didn’t have to implement this trick – MS did it for you.

WPF rounded corner textbox

@Smolla had a much better answer in his comment on @Daniel Casserly’s answer: <TextBox Text=”TextBox with CornerRadius”> <TextBox.Resources> <Style TargetType=”{x:Type Border}”> <Setter Property=”CornerRadius” Value=”3″/> </Style> </TextBox.Resources> </TextBox> If you want all the borders of TextBoxes and ListBoxes to have rounded corners, put the style into your Window’s or App’s <Resources>.

.NET TextBox – Handling the Enter Key

Add a keypress event and trap the enter key Programmatically it looks kinda like this: //add the handler to the textbox this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress); Then Add a handler in code… private void CheckEnterKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Return) { // Then Do your Thang } }

Disable button in WPF?

This should do it: <StackPanel> <TextBox x:Name=”TheTextBox” /> <Button Content=”Click Me”> <Button.Style> <Style TargetType=”Button”> <Setter Property=”IsEnabled” Value=”True” /> <Style.Triggers> <DataTrigger Binding=”{Binding Text, ElementName=TheTextBox}” Value=””> <Setter Property=”IsEnabled” Value=”False” /> </DataTrigger> </Style.Triggers> </Style> </Button.Style> </Button> </StackPanel>

How to define TextBox input restrictions?

I’ve done this in the past with an attached behavior, which can be used like this: <TextBox b:Masking.Mask=”^\p{Lu}*$”/> The attached behavior code looks like this: /// <summary> /// Provides masking behavior for any <see cref=”TextBox”/>. /// </summary> public static class Masking { private static readonly DependencyPropertyKey _maskExpressionPropertyKey = DependencyProperty.RegisterAttachedReadOnly(“MaskExpression”, typeof(Regex), typeof(Masking), new FrameworkPropertyMetadata()); /// <summary> … Read more

WPF: simple TextBox data binding

Name2 is a field. WPF binds only to properties. Change it to: public string Name2 { get; set; } Be warned that with this minimal implementation, your TextBox won’t respond to programmatic changes to Name2. So for your timer update scenario, you’ll need to implement INotifyPropertyChanged: partial class Window1 : Window, INotifyPropertyChanged { public event … Read more