When using data binding, how do I know when a control was added? - windows-phone-7

When using data binding, how do I know when a control was added?
I'm using ItemsControl element with ItemTemplate.
I want to know when a control was added like event(ex. OnControlAdded)
Please help me

That's not how it's supposed to work, you got it upside down.
You're supposed to have a ViewModel, and Collection in there that you then bind to your ItemsControl.
On that collection, which should be observable, you have a CollectionChanged event. Subscribe to this one, it will fire when elements are added/removed which in turn will make your ItemsControl grow/shrink.

Related

How to add to an ObservableCollection from a different view?

(I'm using Prism Dryloc) My application consists of two views. The first contains a single list view displaying strings and the second - an entry and a button.
The listview is bound to an observable collection in the first page's View Model. How can I add to the observable collection from a different view?
Great question! You're essentially trying to pass data between views, and there's several ways of passing data between Views in Xamarin.Forms.
The two ways that seem relevant for your case:
Either making the ObservableCollection a public static object (so there's only one global instance of it). Not recommended.
The better way is to use the messaging center so that the second page publishes an event when the button is pressed, that the first page is subscribed to. And it passes that information that gets added to the list.
If these don't work, elaborate your use case and I'll suggest some more

Monotouch dialog- Multiple textfield in single element?

I am using Monotouch dialog with Mvvmcross. My requirement is to have multiple textfield in single element/cell. But in Entryelement we have only one value property which has by default two way binding. Rest of the property are with only one way binding.
I have also tried with UIViewElement but same thing I can bind only one way. UI will update based on changes of ViewModel. But if something user will enter into textfield then how to fire ValueChange for it is challenge for me.
It would be good if somebody can point out rough steps to achieve it.

Devexpress detail gridview events not firing

I have a master "gridview" and a detail "gridview" connected to it. The detail "gridview" does not have any columns initially, it loads data from database and it creates its columns.
For example, i'm trying to handle cellvaluechanged event, however, even if i write something in a cell of the gridview and then pressing enter, the event is not firing. What can the reason be?
In my opinion the best way to handle this is: Create a class which represent the data from your database. Let the class implement the interface INotifyPropertyChanged. Then create a BindingList with all Objects from your Database. Now use this BindingList as DataSource for your Grid. The BindingList got the Event ListChanged. This will recognize that a Property Value in your DataSource is changed if you type some new value in cell.
I think this is best practice because you are working with your DataSource and not with GridView directly.
Otherwise the event should fire for sure. If you cant use my idea send some code, maybe i can find the problem then.
regards

Deleting a collection when closing a CollectionView in Backbone.Marionette

After closing a CollectionView in my project, the collection it makes reference to is still available. Opening again the CollectionView duplicates the collection as it reloads the data again. I think this is expected behaviour as in the documentation it says that all the CollectionView does on close is:
unbind all listenTo events
unbind all custom view events
unbind all DOM events
unbind all item views that were rendered
remove this.el from the DOM
call an onClose event on the view, if one is provided
I'm guessing it's on me to manage the collection on the onClose event handler. Is there a good way of deleting the collection and models associated with the view?
In your situation it's not necessary to delete the collection. Variables (in this case your collection) that are not directly referenced by another object will be garbage collected by javascript. So when the view and module close and nothing else is referencing the collection it will be removed.
If you want to make absolutely sure you won't get any zombie events you can clear it's event listeners when you close the module and/or view:
myCollection.off();
Of course is your collection is a global variable (technically a property of the window object) then yes it might be a good idea to delete it like so:
delete window.myCollection;
Aside from this, removing it from memory is not something you need to worry about as the other objects referencing are closed...

Unify ViewModel through-out UserControl

I'd like to know how to set a single ViewModel throughout a single UserControl. I'm using an Items container inside a user control (bound to ItemsSource) and it doesn't seem to update with the code-behind replacement of a DataContext (to a code-behind instantiated ViewModel)
What i'm trying to do is change the DataBound foreground color of every text Item in the userControl, and the items inside an Itemscontrol dont seem to change. forcing a datacontext change removed the collection items from display.
I think I'm conceptually Misunderstood here. could anyone help?
I could fix the problem by using Storyboards to change color but the problem was still the same. The eventual solution was to access the resources inside the templates, which is possible by browsing the Visual Tree as shown in this tutorial
http://windowsphonegeek.com/tips/how-to-access-a-control-placed-inside-listbox-itemtemplate-in-wp7
The peculiar thing though, was that I needed to look for my object inside the initial object returned, as it seems to return the System generated one, which you don't see yourself. Looking for the answer inside this one helped. Also, pushing them into a list of items for easy access later could be a general idea, but MS needs to fix the way of doing this pronto.
I would recommend binding the ItemsSource to a property in your ViewModel.

Resources