Hi,@Sgcino Ngema. Welcome to Microsoft Q&A.
Note: The space bar is also a normal input in a TextBox.
If you want to enter data without preserving space bar, you could try using Trim().
Here is a reference example:
<Grid>
<TextBox x:Name="txtLocationName" Grid.Column="3" Grid.Row="5" Height="22" VerticalAlignment="Center" TabIndex="17" IsEnabled="{Binding BoolEnableLocationName}"
Text="{Binding Path=StrSearchLocationNameCaller, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=True}"
PreviewKeyDown="txtLocationName_PreviewKeyDown">
</TextBox>
</Grid>
public partial class CaptureUC : UserControl,INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string strSearchLocationNameCaller;
public string StrSearchLocationNameCaller { get { return strSearchLocationNameCaller; } set { strSearchLocationNameCaller = value.Trim(); OnPropertyChanged("StrSearchLocationNameCaller"); } }
private bool boolEnableLocationName;
public bool BoolEnableLocationName { get { return boolEnableLocationName; } set { boolEnableLocationName = value; OnPropertyChanged("BoolEnableLocationName"); } }
public CaptureUC()
{
InitializeComponent();
BoolEnableLocationName = true;
this.DataContext = this;
}
private void txtLocationName_PreviewKeyDown(object sender, KeyEventArgs e)
{
}
private void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.