I'm creating a WPF application using MVVM. I'd like to make it so all textboxes in the application, by default trims the text.
I have tried to follow the answer here
I managed to add System.Windows.Interactivty reference via NuGet. I created a UserControl in a behaviors folder and copied the provided code. But Visual Studio cannot find suitable method to override, and AssociatedObject does not exist.
And in the XAML, it does not like <local:TrimTextBoxBehavior />
or xmlns:local="clr-namespace:StaffApp;assembly=mscorlib"
or xmlns:local="clr-namespace:StaffApp.Behaviors;assembly=mscorlib"
I have tried a different method of trimming all the binded properties' setters in my Model
e.g. public string MiddleNames { get => _middleNames; set => _middleNames = value.Trim(); }
But I'm not a fan of having to do this for every property, and this causes issues when the textbox is null as defined from my XAML form:
<Label Width="100" Content="Middle name(s)" />
<TextBox Text="{Binding Employee.MiddleNames, TargetNullValue=''}" />