reactiveui / ReactiveUI

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
https://www.reactiveui.net
MIT License
8.1k stars 1.12k forks source link

Why? this.WhenActivated Prompt error #2445

Closed eighteen-k-gold-malow closed 4 years ago

eighteen-k-gold-malow commented 4 years ago

code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ReactiveUI;
using DynamicData.List;
using DynamicData;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Collections.ObjectModel;

using LeboGame.Models;
using System.Diagnostics;

namespace LeboGame
{

    public partial class MainWindow : Window, IViewFor<AppViewModel>
    {
        public MainWindow()
        {
            InitializeComponent();

            this.WhenActivated(disp =>
            {
                Debug.WriteLine("View - Activate");
                Disposable.Create(() => Debug.WriteLine("View - Deactivate")).DisposeWith(disp);
            });

        }

        public AppViewModel ViewModel { get; set ; } = new AppViewModel();
        object IViewFor.ViewModel { get => ViewModel; set => ViewModel = (AppViewModel)value; }

    }
}

model

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;

using ReactiveUI;
using DynamicData;

namespace LeboGame.Models
{
    public class UserDataItem
    {
        public bool Check { get; set; }
    }

    public class AppViewModel : ReactiveObject
    {
        public AppViewModel()
        {
            UserData.Connect()
                .Bind(out _userDataList)
                .Subscribe();
        }
        public SourceList<UserDataItem> UserData = new SourceList<UserDataItem>();
        public readonly ReadOnlyObservableCollection<UserDataItem> _userDataList;
        public ReadOnlyObservableCollection<UserDataItem> UserDataView => _userDataList;
    }
}

error info

System.ArgumentException:“Don't know how to detect when LeboGame.MainWindow is activated/deactivated, you may need to implement IActivationForViewFetcher”
open-collective-bot[bot] commented 4 years ago

Hey @crud-boy :wave:,

Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider contributing financially.

https://opencollective.com/reactiveui

PS.: We offer priority support for all financial contributors. Don't forget to add priority label once you start contributing :smile:

ReactiveUI - Open Collective
An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms!
glennawatson commented 4 years ago

Got reactiveui.wpf installed or appropriate platform project?

https://www.reactiveui.net/docs/getting-started/installation/

Installation
github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.