[英]How do I set page content using Prism and Xamarin.Forms?
So, currently in my MainPageViewModel, I have something like this: 因此,当前在我的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
};
}
Where MainPageViewModel inherits from BindableBase... However, I also want it to inherit from ContentPage, so I can set the page content to my wraplayout. MainPageViewModel从BindableBase继承的地方...但是,我也希望它从ContentPage继承,因此可以将页面内容设置为我的wraplayout。 However, it won't allow me to inherit from two base classes.
但是,它不允许我从两个基类继承。
I'm confused on how to proceed then? 那我对如何进行感到困惑?
Here's my XAML: 这是我的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>
What can I do in this scenario? 在这种情况下我该怎么办? I want to bind to the tile in my xaml (have MVVM structure) but also set content page.
我想绑定到我的xaml(具有MVVM结构)中的图块,但还要设置内容页面。
You've completely missed the entire point of MVVM. 您已经完全错过了MVVM的全部内容。 Your ViewModel should NEVER EVER have any View or any understanding of the View.
您的ViewModel绝不应该具有任何视图或对该视图的任何了解。 The entire point is loosely coupled code allowing a separation of concerns.
整个要点是松散耦合的代码,允许分离关注点。
I suggest that you head over to the Prism Samples for Xamarin Forms to get a better understanding of how to properly set up an app. 我建议您前往Xamarin Forms的Prism Samples,以更好地了解如何正确设置应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.