【问题标题】:ReactiveUI Example with Avalonia : UserControl View not workingAvalonia 的 ReactiveUI 示例:UserControl 视图不起作用
【发布时间】:2021-03-13 16:22:56
【问题描述】:

我尝试使用带有 ReactiveUI 的 Avalonia 来实现 Reactive UI Example。搜索有效,我可以在控制台上打印由此产生的元素,并且 UI 中的每个元素都有一个“插槽”(行出现但为空),但 NuggetDetailView 不显示为列表的项目。

我已在我的 Avalonia 应用程序的 Initialize 方法中激活 View 以进行 ViewModel 扫描:

    public class App : Application
    {
        public override void Initialize()
        {
            AvaloniaXamlLoader.Load(this);
            Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly());
        }
    ....
    }

我没有收到任何错误,所以我对自己做错了什么有点迷茫。

提前谢谢你,

【问题讨论】:

  • App 和你的意见是同一个项目吗?
  • 是的,确实如此,这就是我希望扫描能够正常工作的原因。但我不介意手动添加课程

标签: c# .net-core mvvm reactiveui avaloniaui


【解决方案1】:

原来基于反射的视图扫描不起作用。 我变了

Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly());

Locator.CurrentMutable.Register(() => new NugetDetailsView(), typeof(IViewFor<NugetDetailsViewModel>));

成功了

【讨论】:

  • 程序集扫描代码似乎很简单github.com/reactiveui/ReactiveUI/blob/… 如果您的视图实现IViewFor 或继承自ReactiveUserControlReactiveWindow,则自动注册应该完全有效
  • 我的控制扩展ReactiveUserControl
猜你喜欢
  • 2022-01-04
  • 2021-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-15
  • 2016-07-21
  • 2022-12-22
相关资源
最近更新 更多