When you bind to a collection in WPF it actually always binds to a CollectionView that is itself connected to the actual collection. For example, if you bind an ItemsSource to an ObservableCollection it will actually bind to a CollectionView that itself points at the specified ObservableCollection.
Does WinRT do the same thing/similar thing or does it bind directly to specified collection?
Turns out the answer is no, it does not happen automatically. But you can still get a CollectionView for your ObservableCollection and then find that against the ItemsSource. So can extra step is required.
Related
I'm using useContext and setState hooks to share an array of audiotracks across my site. i have a few playlist components which can add/remove tracks to the global playlist as well as a wrapper for the audio element that can e.g. retrieve next track when current finishes.
The playlists all use the same Component. Each Track is basically just a <tr> with <td>s containing id,title,url.. and so on. I generate these using json.
Now my question is what should I pass around in my hooks? Because I see at least 3 options... I could pass the
passing track_id seems most efficient but.. but whenever I need the tracks data.. e.g. to get the url or to render I need to find the object which could be anywhere nested in my json backend.
passing the dom-node seems wrong... but would be very easy to use in case i want to render the list somewhere else.
if you pass the track json object.. I have all the data I need at any point.. but i somehow need to attach it to all track dom nodes.. and that again seems not right too..
Option #1. track.json object
{"title":"...","artist":"...","year":"..."}
Option #2. <tr> dom-node
<tr><td>title</td><td>arist</td><td>year</td></tr>
key={track_id}
Now I would obviously like to follow best-practice and be as efficient as possible.. so can somebody point me in the right direction
I think all will do the same thing. If you pass an id or json then it will still need to be rendered in a dom node to be viewed, so when you say pass a dom node your really just passing a string. Am I correct in saying that no matter what is passed it will need to go through some sort of function to get the song from the back end? If so, then my suggestion would be json.
I'm using asp.net core to create a webapi project.
When an object is posted to my action, I want to use the custom converter to analyse the json object first.And then create an instance of a child class. For the child, instance I only want to customize one property. So the question is, what if the object gets complex, I want to use the standard conversion to get the whole object, and manually manipulate one property.
What is the best way of achieving this?
You can add only the properties you want to your View Model, the rest will be ignored.
I eventually figured this out. For all the properties that you don't want to use custom deserialization you can still use the string.ToObject() to convert. Just do not use ToObject method on the very class that you originally created the converter for. It will craete an infinite loop trying to convert itself again and again.
I am getting the data from server in JSON and I am converting that to my viewModal. Now I am loading the a new view using return router.navigate('results'). But at the same time I want to pass the viewModel which I created from the JSON object to be passed to this view. By default the "results" viewModel is getting called but it is having blank values.
A small code snippet will be helpful as I am new to Durandal JS.
The best answer I have is to store that information in a separate module, like so:
storage.js
define(function(require) { return []; });
viewmodel.js
define(['storage'], function(storage) {
$.get('uri', function(data) {
data.forEach(function(obj) {
storage.push(obj);
});
});
});
This is not the most elegant solution. I'm really interested if there is a clean way to pass data from and to separate view models on activation, but so far I have found none.
Ended up finally something like this.
In the module where I want to navigate, I created an "Initialize" function which accepts a JSON object. Using this JSON object I initialized all properties in the viewModel.
From the page from where I have to navigate there I did a "require" on the module where I want to navigate next. Then I called the "Initialize" method and passed my JSON object.
After this I used router.navigate method to go that module.
This way when I navigated, I got all the values which I wanted to pass from one view to other. Hope this approach will help someone else.
The answer from Matthew is certainly similar to the way that I currently do it, once the data is held within your separate module (i have a path called modules/data/someDataStorage) you can use either events or a knockout observable to make the data update through to your view models.
In your case I would make updates to your shared module to store information on your request and then on the activation of your results module, go and get the data from that shared module.
I need to serialize every control of a .NET managed process (whether it's main form, child controls like buttons, calender, text boxes, list boxes, combos, etc). Every simple class object is easily serializable/deserializable using binary formaters, but these controls (which I got their info through reflection(Type.GetFields(), Type.GetProperties())) are not serializing through this serialization method which I described.
It throws a "type System.Forms.Form.WinForm to be serialize" exception. After serialization I need to pass the control's information as it is, to another remote process.
How can I get the .NET control's information to be serializable? (Json?)
I believe http://www.codeguru.com/forum/archive/index.php/t-421612.html has an answer for you
I have a custom container (C#) for the Flash ActiveX control and am passing data back and forth. Previously I would use ExternalInterface.call and pass an Array as a parameter. I would prefer to use the Vector class now that it is available, but it appears that when I do that the call is never made.
It is however made if it is embedded in IE. It appears that when in IE, Flash will send out JavaScript to execute rather than serializing to XML. My guess is that the Vector XML serialization isn't baked in, so Flash just ignores the call.
Anyone have any ideas? Other than just going back to using Array, I've already done that for now.
The docs note that:
Other built-in or custom classes -
ActionScript encodes other objects as
null or as an empty object. In either
case any property values are lost.
It's not completely clear what that means, since custom classes are also Objects - I guess only vanilla objects count? But at any rate it looks like Vector falls into that "other built-in classes" category, so you'll need to either use Array, or re-cast to Array before you pass the data.
you can use arrays with [ArrayElementType("type")] instead. or write a serialization function for Vector