In the window there is a button whose IsEnabled property should be true only if the Text in the TextBox matches the Regex pattern. In other cases, false . You also need to follow the MVVM pattern.
View.xaml
<Button Content="CLICK!" Height="45" IsEnabled="{Binding NameIsValid, Mode=OneWay}" Width="127" /> <TextBox Height="32" Text="{Binding Name, Mode=OneWayToSource}" FontSize="20" Width="120"/> ViewModel.cs
public bool NameIsValid { get { return new Regex(@"^([AZ]|[А-Я]|І|Ї)([az]|[а-я]|і|ї)+").IsMatch(Name); } } public string Name { get => user.Name; set { user.Name = value; OnPropertyChanged("Name"); OnPropertyChanged("NameIsValid"); } } When a valid value is entered into the TextBox IsEnabled property of the button is not updated, but remains as it was at startup.
How to update the property of an element when changing another in my case?
PS
Found that the update happens only when the TextBox is out of focus. Is it possible to see updates immediately when typing?
NameIsValidabout the getter of this propertyNameIsValid, it is called after thisOnPropertyChanged("NameIsValid");? - tym32167 9:10 pmreturn new Regex(@"^([AZ]|[А-Я]|І|Ї)([az]|[а-я]|і|ї)+").IsMatch(Name);, change the text in the textbox and tell me, did breakpoint work or not? - tym32167