简体   繁体   English

如何使用Prism和Xamarin.Forms设置页面内容?

[英]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 FormsPrism Samples,以更好地了解如何正确设置应用程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 xamarin.forms 中的 viewcell 中设置按钮以从内容页面 viewmodel 调用命令? - How do I set a button in viewcell in xamarin.forms to call a command from the content page viewmodel? 如何在Xamarin.Forms中使用Prism在页面之间导航? - How to navigate between pages using Prism in Xamarin.Forms? 如何使用Prism / DryIoC在Xamarin.Forms中解决IValueConverter中的依赖关系 - How to resolve a dependency in IValueConverter in Xamarin.Forms using Prism/DryIoC 如何使用“ Xamarin.Forms”中的“ Prism.Forms”绑定视图和查看存在于不同dll中的模型? - How to bind views and view models that exist in different dlls using “Prism.Forms” in “Xamarin.Forms”? Xamarin.Forms Prism-使用导航服务从一个详细信息页面导航到另一个 - Xamarin.Forms Prism - Using navigation service to navigate from one detail page to another 如何在WebView Xamarin.Forms中加载带有javascript内容的HTML页面? - How to load HTML page with javascript content in a WebView Xamarin.Forms? 如何使用 Prism 对 Xamarin.Forms 中的按钮按下和释放事件进行松散耦合? - How to do loose coupling of button pressed and released events in Xamarin.Forms with Prism? 使用Prism框架隐藏Xamarin.Forms中的选项卡 - Hiding a tab in Xamarin.Forms using Prism framework 如何使用Prism在Xamarin.Forms中自动注册视图 - How to register views automatically in Xamarin.Forms with Prism Xamarin.Forms 和 Prism - 如何传递数据并导航到另一个视图? - Xamarin.Forms and Prism - How to pass data and navigate to another view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM