如何使用 Prism 和 Xamarin.Forms 设置页面内容?
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 永远不应该有任何视图或对视图的任何理解。重点是松散耦合的代码,允许关注点分离。
我建议您转到 Prism Samples for 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 永远不应该有任何视图或对视图的任何理解。重点是松散耦合的代码,允许关注点分离。
我建议您转到 Prism Samples for Xamarin Forms 以更好地了解如何正确设置应用程序。