M Yil
M Yil

Reputation: 957

Xamarin Forms with ReactiveUI - Changes to xaml.g.cs is lost, causes by ReactiveUI bug

I have a Xamarin forms application based on the tabbedpage structure. The tabbedpageview view doesn't inherit from tabbedpage but it inherits from ReactiveTabbedPage like this:

public partial class PlanningDetailPage : ReactiveTabbedPage<PlanningDetailViewModel>

When doing that, the xaml.g.cs file gives an error:

Using a generic type EactiveTabbedPage<TViewModel> requires 1 type arguments

See image below:

enter image description here

When I change that to this:

    public partial class PlanningDetailPage : global::ReactiveUI.XamForms.ReactiveTabbedPage<PlanningDetailViewModel> {

The changes are lost after some time. Why is that, and how can I fix this issue?

Upvotes: 1

Views: 146

Answers (1)

Lucas Zhang
Lucas Zhang

Reputation: 18861

If your Page is a subclass of ReactiveTabbedPage , you need to define the ViewModel of it ,like

using ReactiveUI.XamForms;
using ReactiveUI;
public partial class TabbedPage1 : ReactiveTabbedPage<MainViewModel>
{
    public TabbedPage1()
    {
        InitializeComponent();

        this.ViewModel = new MainViewModel();

    }
}

public class MainViewModel : ReactiveObject
{
    //...
}

in xaml

<?xml version="1.0" encoding="utf-8" ?>
<rxui:ReactiveTabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:rxui="clr-namespace:ReactiveUI.XamForms;assembly=ReactiveUI.XamForms" xmlns:local="clr-namespace:App24"
             mc:Ignorable="d"
             x:Class="App24.TabbedPage1"
             x:TypeArguments="local:MainViewModel">
  <!--Pages can be added as references or inline-->

</rxui:ReactiveTabbedPage>

Upvotes: 3

Related Questions