Home > OS >  Unable to handle a window event in Visual Studio [closed]
Unable to handle a window event in Visual Studio [closed]

Time:09-16

I´m developing a WPF desktop application in C# VS 2019 with .net5.0. I catch the window StateChange event. The event data has type EventArgs, which is just a base class with no usefull info about the event. I want to use cast to ViewStateChangedEventArgs. This class is located in namespace System.Activities.Presentation.View, but this namespace is not included in VS 2019/.net5.0. My first question is: have I selected the right subclass for event data ? The namespace is located in System.Activities.Presentation.dll which is a part of .net4.x and resides under x86 components, outside VS. In VS 2019 WPF it is not possible to add a reference (or whatever this component could be) from outside VS, you just cannot freely browse the PC. How can I add and use this dll in my VS 2019/.net5.0 project ?

CodePudding user response:

Looking at the documentation, the StateChange is of type EventHandler, i.e. it does not contain any meaningful data. And as far as I can tell, the actual argument is just an EventArgs not ViewStateChangedEventArgs. I'm not sure why you think you could cast it to a ViewStateChangedEventArgs, but that is probably not the way to do it.

Instead just check the WindowState property. If you need the old state you can save this to a field in the constructor, and update it whenever StateChange is raised.

  • Related