Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can preview lang in design time #2

Closed
Cricle opened this issue Jan 11, 2022 · 4 comments
Closed

Can preview lang in design time #2

Cricle opened this issue Jan 11, 2022 · 4 comments

Comments

@Cricle
Copy link
Owner

Cricle commented Jan 11, 2022

No description provided.

@Cricle Cricle added the feature label Jan 11, 2022
@flier268
Copy link
Contributor

I had a solution,
2 Step:

  1. add a new class just for design time, override the origin viewmodel
public class DesignViewModel: ViewModel
{
  public DesignViewModel():base()
  {
    // load resource from file
    //LanguageManager.Instance...
  }
}

modify Lang.cs from

public class Lang : MarkupExtension
{
  //...
  public override object ProvideValue(IServiceProvider serviceProvider)
  {
    //...
  }
}
public class Lang : MarkupExtension
{
  //...
  public override Binding ProvideValue(IServiceProvider serviceProvider)
  {
    //...
  }
}

@Cricle
Copy link
Owner Author

Cricle commented Oct 21, 2022

image

public class DesignViewModel
{
    public DesignViewModel()
    {
      var ser = LanguageManager.Instance.LangService;
      var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Strings");
      var zhNode = ser.EnsureGetLangNode("zh-cn");
      zhNode.AddJsonFile(Path.Combine(path, "zh_cn", "hello.json"), false, true);
  }
}

Thanks @flier268 !

@flier268
Copy link
Contributor

不客氣,順帶一提,Avalonia的正式版在axaml上不能用,preview可以有空的話請更新一下

@Cricle
Copy link
Owner Author

Cricle commented Oct 21, 2022

不客氣,順帶一提,Avalonia的正式版在axaml上不能用,preview可以有空的話請更新一下

Thanks a lot

Cricle added a commit that referenced this issue Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants