[英]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.