Get the loaded instance of the code behind of ResourceDictionary - code-behind

I've made a resource dictionayry for a user control and create a class that derived from ResourceDictionary that managed different eventsetters and handlers for controls contained in the resource dictionary. So far so good, everything is working fine. My problem is to access members contained in my ResourceDictionary class from the user control. How to access a property in ResouceDictionary object from the user control?
Thanks a lot!
Ben

I finally find a way to handle it. I create a variable of my resourcedictionary type that handle also his events. After, I set the resource dictionary to the control by code with my variable. So now, I can handle events declared in my resource dictionary.
If someone need to see codes needed to get the job done, let me know.

Related

MVVM - Share encapsulated model with other VMs

In my Windows Phone App there's a simple hierarchical model consisting of a class containing a collection of other domain objects.
In my xaml i have declared an ItemsContainer control that renders the items in the above mentioned collection as simple rectangles.
Now, at the VM level i have a structure that resembles my model with a parent VM having a collection of children VMs. Each child-VM encapsulates its own model.
Whenever the user taps the view bound to a child-VM a method of the parent-model object should be invoked taking the relevant child-model as parameter. This will in turn change some internal state that will be reflected (possibly) on all the child-views (not just the tapped one).
SO... given that i'm using the MVVM Light framework my current implementation is as follows:
Child-VM exposes a command
The command Execute method will use the messenger to notify the parent-VM of the tap event. The message (GenericMessage class) content will be the domain object encapsulated by the VM
The parent-VM executes the method of the parent-model using the message content as parameter
If the operation succeeds the parent-VM sends a new message to inform child-VMs of this fact. Once again the message content is the model object used as parameter in the method that was just invoked
Child-VMs raise a couple of PropertyChanged events that, finally, will update the bound views
It works but i fill it's a bit cumbersome. The thing that bugs me the most is the fact that when a child-view is tapped the associated VM will broadcast its encapsulated model object. Do you feel that there would be a better way of implementing such a system?
Thanks in advance for your precious help
Could you not just put the command on the parent viewmodel and pass the child viewmodel as the command parameter?
The parent view model can then just call methods on the child viewmodels to update them. I'm not sure I see the need for all these messages?

SharedObject and Dictionary problems in Flash Builder

I'm usin Flash Builder to create some actionscript code that uses SharedObjects.
First question: how can I delete my local SharedObject in Flash Builder? I am debugging my program and the SharedObject sems to persist between runs. I want to start fresh and clean with no SharedObject storing my data. How do I get rid of it?
Also, in my SharedObject, I used mySharedObject.data["mykey"] to store a Dictionary. This Dictionary will have String keys and values of MyCustomClass. The problem is that when I later try to loop over the values of this Dictionary, I get error #1034 cannot convert object to type MyCustomClass. It seems like I can put an item of type MyCustomClass into this dictionary, but I can't get the item back out as anything other than an object.
Any idea what is going wrong?
Those are essentially two questions, so should have been asked as two questions. Anyway, I'd answer them here but still prefer that you break them up in two parts (possibly leave a link to the other one here for reference sake):
Local shared object, are useful exactly for persistence across runs. And then there's SharedObject.clear() to clear the state as required.
For you second issue, Shared Object's serialize your object into AMF, so that it can be written to disk or sent over network using RTMP. Now, your custom class can't really be serialized in AMF. What actually happens is that the public properties (and dynamic ones, if the class is declared dynamic) are serialized into the structure. So, the public data is stored... but it's essentially a general Object.
To work around that, you can have a public static readFrom(object:Object):MyCustomClass type function, which would read the properties from the passed object to construct a new MyCustomClass representing that information.
There are ways to register your class with the player to be stored in SharedObject (see here)... but you need to make sure that the code that de-serializes that data is aware of the class as well.
To make a class available for conversion, in your global initialization use registerClassAlias() call with MyCustomClass and its fully qualified name as parameters. The manual. Say your custom class is foo.bar.TheClass, you write:
registerClassAlias('foo.bar.TheClass',foo.bar.TheClass);
In order to drop old SO use delete call against so.data["mykey"] and do so.flush(). Edit: SharedObject.clear() is way better.
1/ Being persistent is one of the particularity of a SharedObject. To cleanup all its content, you need to call the clear method.
var shareObject:SharedObject = SharedObject.getLocal('justatest');
shareObject.data.test = 'test';
trace(shareObject.data.test)
shareObject.clear();
trace(shareObject.data.test)
output
test
undefined
2/ To store complex data types in SO, you need to use flash.net.registerClassAlias (example here)

AS3 How to Synchronize an event

I am attempting to build a small chat application using a remote shared object (RSO) for FMS. My question is, how do you dispatch the SyncEvent when the RSO has been updated? Example, what I want to do is to update all the clients connected when a user enters or leaves a chatroom. I have looked for documentation on this but to no avail. If you can provide me a small example how to do this I would appreciate it.
Thanks
You do not have to dispatch the SyncEvent manually as it is done automatically by the shared object itself when you add a property to it or update the value of an existing property.
Note that if you set a property of your shared object to the same value it had before, no event will be dispatched.
You can find an example of use there.

Dojo DataGrid and CsvStore

I'm using Dojo 1.7 and I have a problem with the dojox/grid/DataGrid and dojox/data/CsvStore. I want to create a dojo DataGrid that responds to text input from the user. The user would type in something that is in CSV format into the text area and the CsvStore would read that data and feed it to the DataGrid but I have a few problems and questions.
CsvStore doesn't always load on time. That is, the _loadFinished property isn't always true when it is time to feed it to the DataGrid. Do I have to use Deferred or something? This object has no event properties as I had hoped.
It seems that DataGrid must absolutely have to have the structure property declared. I'm not sure if this is true can someone please tell me? Is there a way to bypass this? Because if not this leads to my third problem.
If I need to declare my DataGrid structure/layout, I need to know the fieldnames which I need to extract from CsvStore since I have no idea what my data looks like. I'm not sure how to do this because I can't call the internal _attributes property that holds the field names. It seems to me that my best bet is using the getAttributes(item) method but I don't know what item is and according to the documentation, this valuable is required.
Thanks for all your time.
So for anyone interested, this is how I fixed the issue.
Apparently CsvStore and all of the Dojo stores don't use their primary method _processData unless called by some other widget such as the Grid so it belongs on the same thread.
DataGrid must have a structure which is bizarre. I think it should be optional
There was no way to retrieve those fieldnames. I had to use string manipulation (sad-face). Maybe I'm wrong, hopefully someone can tell me how.

JTree Node Names / Group names are not visible

I've written a JTree with couple of nodes. When I launch the program, I only see the node icons like folder or file and not the names associated with them. I could expand and collapse the nodes. When I debug, I see that the nodes are set with proper data whatever I used while building the model. In this program, i've written wrappers for JTree, TreeModel, DefaultMutableTreeNode. What could be the problem? Any pointers would be of great help.
-Paul
Sorry for not posting more details/code. Anyway, I've found the problem with my code. The problem was that I had overridden the toString() method in the class that I use to set as user object for the tree node, but that was returning null. As the method was returning null, there was nothing displayed. I made it to return the string to be displayed. It is working good now.
Thanks guys..!