C#C
C#2y ago
Mek

✅ Conditionally rendering the text and style of a label avalonia

<UserControl>
  <UserControl.Styles>
    <Style Selector="Label"></Style>
    <Style Selector="Label.Success"></Style>
    <Style Selector="Label.Error"></Style>
  </UserControl.Styles>

  <Border>
    <Grid>
      <Grid>
        <Label />
      </Grid>
    </Grid>
  </Border>
</UserControl>
public class LoginViewModel : ViewModelBase
{
    private bool _isSuccess;

    public LoginViewModel() {}

    public bool IsSuccess
    {
        get => _isSuccess;
        set => this.RaiseAndSetIfChanged(ref _isSuccess, value);
    }
}
I have a label that has text that is worked with in the view model. The text that it dislpays is based off the actions of the user. I want to set this label up to where the view model displays the correct message and correct styles based off a boolean value.
Was this page helpful?
✅ Conditionally rendering the text and style of a label avalonia - C#