fsprojects / FsXaml

F# Tools for working with XAML Projects
http://fsprojects.github.io/FsXaml/
MIT License
172 stars 48 forks source link

OnUnloaded is not called in WindowViewController #30

Closed fralken closed 8 years ago

fralken commented 8 years ago

Hello, maybe I'm misunderstanding something, but it seems that the OnUnloaded callback is never called in ViewControllerBase.

I'm using FsXaml.Wpf 0.9.9.

I have a XAML like so (MainWindow.xaml):

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MainWindow;assembly=MyApp"
    xmlns:viewmodel="clr-namespace:ViewModels;assembly=MyApp"
    xmlns:fsxaml="http://github.com/fsprojects/FsXaml"
    fsxaml:ViewController.Custom="{x:Type local:MainWindowController}"
    WindowStyle="None" ResizeMode="NoResize" Background="Black">
...

and a ViewController like so:

/// Top-level container for all XAML elements.
type MainWindow = XAML<"MainWindow.xaml", true>

type MainWindowController() = 
    inherit WindowViewController<MainWindow> ()

    override __.OnInitialized _ =
        base.DisposeOnUnload(someDisposable)

    override __.OnLoaded view =
         // do something

    override __.OnUnloaded view =
         // do something

OnInitialized and OnLoaded are called when the window is created, but OnUnloaded is not called on exit, which means that disposeble objects added to DisposeOnUnload are never disposed. In which case should OnUnloaded be called? Thanks

dvitonis commented 8 years ago

This is a good question. I am also having a hard time finding out how to dispose of everything when closing the app.

ReedCopsey commented 8 years ago

@fralken and @dvitonis I'm working on a major upgrade to FsXaml - please see https://github.com/fsprojects/FsXaml/issues/29#issuecomment-218262194

I think this is more inline with how C# works, and would be nicer moving forward than trying to support the ViewController concept. Thoughts?

fralken commented 8 years ago

Thanks @ReedCopsey, it looks very promising! I'm looking forward to testing it soon. Access to named elements is very useful.

As a side note, I noticed that when I open MainWindow.xaml in VS editor, the application starts, and I see the effects in the application window inside the editor (it uses the Kinect so I see the ouput of the Kinect inside the editor). Why does it behave like so?

ReedCopsey commented 8 years ago

@fralken Beta of 2.0 is just released. See #33 Can you please try migrating your projects and make sure you don't have any issues?

Re: Application window running - that's normal - the VS Designer actually creates an instance of your window. You can check for this, and not create the logic, by checking https://msdn.microsoft.com/en-us/library/system.componentmodel.designerproperties.getisindesignmode.aspx?f=255&MSPPError=-2147217396

Note that with the new 2.0 mechanisms, this should never be an issue. Code behind will actually occur in a subclass, not in the designed type, which should make the issue just go away.