我认为要使Prism.Uno与x:Bind配合使用,需要做什么?

问题描述 投票:0回答:1

我来自WPF / Prism背景,但是我非常喜欢X:Bind提供的功能。使用Prism.Uno时如何使x:Bind与我的ViewModel一起使用?

[我有棱镜:ViewModelLocator.AutoWireViewModel =“ True”,但在理解设计时它的工作原理时,我似乎缺少一些东西。

谢谢G

prism uno-platform winui
1个回答
0
投票

x:Bind的使用要求绑定路径植根于视图中。

要使用DataContext,您需要使其可通过视图键入,如下所示:

public partial class MyControl : INotifyPropertyChanged
{
#if !HAS_UNO 
        // Uno already defines this event (it will be removed 
        // in the future to be aligned properly with WinUI)
        public event PropertyChangedEventHandler PropertyChanged;
#endif

        public MainPage()
        {
            this.InitializeComponent();

            DataContextChanged += 
                (s, e) => PropertyChanged?.Invoke(
                   this, 
                   new PropertyChangedEventArgs(nameof(ViewModel)));
        }

        public MyViewModel ViewModel => DataContext as MyViewModel;

}
© www.soinside.com 2019 - 2024. All rights reserved.