I'm new to Avalonia, so my code should be pretty basic. I have 1 window with 1 panel in it that is:
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center" Width="300">
<TextBlock Text="{Binding Greeting}" />
<TextBox Text="{Binding Name}"/>
<Button Content="Say HI" Click="OnButtonClicked" IsEnabled="{Binding Enable}"/>
That panel has TextBlock, TextBox, and button. The button is not enabled by default. My question is, how can I enable it when the value of textBox is changes. Here is my Model class that already has some basic logic in it:
class HelloViewModel : INotifyPropertyChanged
{
private string greeting = "";
private string name = "";
public bool Enable = false;
public string Greeting
{
get => greeting;
set
{
if (value != greeting)
{
greeting = value;
OnPropertyChanged();
Enable = true;
}
}
}
public string Name
{
get => name;
set
{
if(value != name)
{
name = value;
OnPropertyChanged();
Enable = true;
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}