[英]How do I set a button in viewcell in xamarin.forms to call a command from the content page viewmodel?
[英]How do I set page content using Prism and Xamarin.Forms?
因此,当前在我的MainPageViewModel中,我有类似以下内容:
WrapLayout wrapLayout;
private string _title;
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
public MainPageViewModel()
{
wrapLayout = new WrapLayout();
Content = new ScrollView
{
Margin = new Thickness(0, 20, 0, 20),
Content = wrapLayout
};
}
MainPageViewModel从BindableBase继承的地方...但是,我也希望它从ContentPage继承,因此可以将页面内容设置为我的wraplayout。 但是,它不允许我从两个基类继承。
那我对如何进行感到困惑?
这是我的XAML:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:VideriMediaViewer"
x:Class="VideriMediaViewer.MainPage">
<ScrollView Margin="0,20,0,20">
<local:WrapLayout x:Name="wrapLayout" />
</ScrollView>
</ContentPage>
在这种情况下我该怎么办? 我想绑定到我的xaml(具有MVVM结构)中的图块,但还要设置内容页面。
您已经完全错过了MVVM的全部内容。 您的ViewModel绝不应该具有任何视图或对该视图的任何了解。 整个要点是松散耦合的代码,允许分离关注点。
我建议您前往Xamarin Forms的Prism Samples,以更好地了解如何正确设置应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.