0

I created View and ViewModel

  public class LoginUserViewModel : ViewModelBase
{
    private string _appName;
    public string AppName
    {
        get => _appName;
        set => this.RaiseAndSetIfChanged(ref _appName, value);
    }
    public string AppVersion { get; set; }
    public LoginUserViewModel()
    {
        AppName = LoadConfig().Item1;
        AppVersion = LoadConfig().Item2;
        // var messageBoxStandardWindow = MessageBox.Avalonia.MessageBoxManager
        //     .GetMessageBoxStandardWindow("test", AppName + " " + AppVersion);
        // messageBoxStandardWindow.Show();
    }
    
    (string, string) LoadConfig()
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json",true, true);

        var configuration = builder.Build();
        var name = configuration.GetSection("AppProperties").GetSection("AppName").Value;
        var version = configuration.GetSection("AppProperties").GetSection("AppVersion").Value;
        return (name, version);
    }
}

and View fragment

                <TextBlock Text="{Binding AppName}"
                       FontSize="50"
                       Width="200"
                       Height="100"
                       TextAlignment="Center"
                       Foreground="White"/>

MessageBox show that AppName contain data, but when i run application, TextBlock is empty.

Any ideas?

ErcodY
  • 21
  • 4

0 Answers0