Instantiating an IDisposable class in xaml - SafeHandles - Best way to make Designer friendly?

Locked Instantiating an IDisposable class in xaml - SafeHandles - Best way to make Designer friendly?

  • Thursday, February 03, 2011 7:18 PM
     
     

    I have a class, OpenDevice, which gets a SafeHandle to a hardware device via P/Invoke and implements IDisposabe. This should be kept alive for the life of the application.

    I would like to use the designer with live data coming from the hardware for some WPF graphic magic. (This data, which I will bind to, is exposed as properties in a view model class.)

    How or where should I instantiate OpenDevice in a Designer friendly way and where and when should I call Dispose on that class?

     

All Replies

  • Tuesday, March 06, 2012 2:18 PM
     
     

    I have the same issue.  I've got WPF objects which have disposable resources (e.g. an ObservableCollection that links itself to a data model) that need to be disposed of when they are no longer in scope.  I've tried using the destructor, but that doesn't seem to ever be called.

    Any ideas on how to dispose of resources in WPF objects?


    Sincerely, Donald Roy Airey