我可以将MvvmCross ViewModel绑定到ViewModel吗

时间:2020-08-26 00:10:40

标签: xamarin mvvmcross

以下是从json反序列化的模型类。

public class JsonQuestion
{
    [JsonProperty("query")]
    public string Query { get; set; }

    [JsonProperty("defaultAnswer")]
    public bool DefaultAnswer { get; set; }

    public bool Answer { get; set; }
}

我已经为iOS和Android创建了通用列表视图,可用于设置开关单元,文本输入单元,按钮单元等(类似于此https://github.com/bcylin/QuickTableViewController

这是我的列表行模型对象的示例。

public class SwitchRowModel : MvxNotifyPropertyChanged, IRowModel
{
    public string Label { get; set; }
        
    private bool _isTrue;
    public bool IsTrue
    {
        get => _isTrue; 
        set => SetProperty(ref _isTrue, value);
    }

    public SwitchRowModel(bool isTrue, string label)
    {
        _isTrue = isTrue;
        Label = label;
    }
}

现在让我们说一个简单的视图模型如下:

public class SimpleViewModel : MvxViewModel
{

    public IList<JsonQuestion> Questions { get; set; }

    private IList<SwitchRowModel> _items;
    public IList<SwitchRowModel> Items {
        get => _items;
        set => SetProperty(ref _items, value);
    }
}

tableview / recyclerview源绑定到Items对象。并且tableview / recyclerview的行绑定到SwitchRowModel对象。我可以将SwitchRowModel对象绑定回JsonQuestion对象吗?

是否可能出现这种情况?或者设计不当?

0 个答案:

没有答案
相关问题