Hello All...
I'm trying to use an example right out of the Project Tracker App.. I create a WPF user control derived from the EditForm base. I can then in the code base attach events to delagates within the code base with the following code.
Dim dp As Csla.Wpf.CslaDataProvider = TryCast(Me.FindResource("Controller"), Csla.Wpf.CslaDataProvider)
AddHandler dp.DataChanged, AddressOf DataChanged
However if I attempt to access the object like this; I get an object Nothing returned.
Dim objCtrlr as MyObjects.ControllerObject = TryCast(Me.FindResource("Controller"), MyObjects.ControllerObject)
Any ideas people?? I have seen this done in many code bases... So it should work.. Let us know... :)
There are two possibilities.
You may consider (temporarily) breaking that line into two lines so you can debug more easily:
Dim tmp As Object = Me.FindResource("Controller")
Dim objCtrlr = TryCast(tmp, MyObjects.ControllerObject)
Thanks for the reply Rocky. As I said before; while hooking the events to delegates it works fine with the same name.. So 'Controller' does exist. I thought of doing this, and I'm not really sure why I haven't tried it yet.. I will try this..
Just going off onto another thought, when you define a resource on the page; and find that resource. You should be able to Cast that object as any named object that the resource either defines, or inherits.. Correct??
-G
Ok, here is what I'm getting after trying the above attempt...
dim obj as Object = FindResource("Controller")
The object returns as Csla.Wpf.CslaDataProvider
Then when attempting the TryCast it fails... Mainly because I believe I'm hitting a proxy to the class that I am trying to capture...
Any ideas???
What is the class defintion for ControllerObject?
Sergey.
So you don’t expect to get a CslaDataProvider?
You should be able to cast the object using normal .NET rules.
Which means you can cast it to its own type, to anything it inherits from or to
any interface it implements.
You can’t cast it to a subclass type, unless you
specifically know that it IS that subclass.
Rocky
All I can say is that I was correct in my assumption that I should be able to cast the object.. The only issue is that I have to cast the Property on the Container object... DUH... Can you tell that I've been working WAY too much this week?? 40 hours and going and it's just Thursday at 9am!
The answer is as follows...
Dim dp as Csla.Wpf.ClsaDataProvider = TryCast(Me.FindResource("Controller"), Csla.Wpf.CslaDataProvider)
dim _ctrlr as MainDisplayController = TryCast(dp.Data, MainDisplayController)
And wow, magically data... I think I could drive a spike through my head at this point and it wouldn't effect my cognitive thinking process...
-G
Copyright (c) Marimer LLC