In Silverlight, I have a collection of tab items. On clicking of a button, I am adding a new tab with a control as content in the collection and showing it to the screen. Now, I have a "Close" button in the screen, calling which, the current visible tab removes from the collection and thus no longer visible in the screen.
I noticed that, though the tab item has been removed from the collection from the tab item and collection, the destructor of the control part of the tab is not getting call all the time. And sometime, it is getting called after a long time (not always).
Though the item has been removed, why it is taking time to call the destructor of the object? How can I resolve this issue? Any pointers?
The destructor of the object called by Garbage Collector, when it seems necessary. Programmer should not rely on the immediate calling the destructor.
Related
I have just started using visual studio c++ (2010) with windows forms, but have cannot for the life of me find out how to create new UI items in response to events. What I would want to happen is click a button, and have a new row, with a couple of text boxes and buttons appear, with onebutton to delete the row if I keep clicking, more rows will appear, named row0, row1 etcv. I looked at this page, (http://msdn.microsoft.com/en-us/library/aa984255(v=vs.71).aspx), about adding controls programmatically, but when I add a new text box inside a click event, the text box is only created inside the scope of the event (as expected!), but I want to be able to create it insde the newRow click event, but access it and . I thought of making a 'row' class, with row.text and row.deleteButton properties, and at each creation of a row, respective events will be created for button clicks and text edits.
Is there anyway to do this, ie a function that can be created that creates new objects by passing the required name?
The trick for this to work is that you need to have declarations outside of the event handler to keep track of the newly added UI components. In the link you've given the added TextBox is locally scoped within the event function, and this will be removed from the heap (i.e. memory) when the event is finished.
So one solution would be to add a list of UI components to your form, and then have the events add to or remove from this list of components. To get this solution working you possibly need to read up on lists of objects (or possibly dictionaries) and how to handle these.
Sorry for a rather general answer, but the question is also very broad... :)
I have a ComboBox implemented with an auto-completion system. My ComboBox contains more than 100 items. When users are typing text in, the auto-completion system opens the dropdown list and highlights the most relevant item. Moreover, when the dropdown list is expanded, all items are available (no filters). But the most relevant item is always at the bottom of the dropdown list.
I would like it to be in the middle, if possible. One item can have the same reference but another type than another one, that's why I need to see most of them in my dropdown by placing them in the middle.
Any idea ? It's not really important but kind of useful for them. Thanks !
Update :
Here's my ComboBox with the open dropdown. Sorry about that, I had to blur its elements. As you can see, the user starts writting the reference in the ComboBox. The autocompletion works fine, but the corresponding item is found at the end of the dropdown list (in the red frame), almost out of bounds.
I wish it would be highlighted in the middle of my dropdown list instead of so far below.
Your item search may work well, but your list isn't visually filtered, which means it's size always remains the same.
It's scrolled into view, by the wpf system, but still displaying all other items around the relevant one. The reason why it's at the bottom is because wpf Scrollviewer just finished scrolling the item into view and sees no need to scroll it further into the middle.
You could use the CollectionViewSource class. Why ?
It's simple to use, will keep your viewmodel data as it is, and you would have your relevant completion item at the top. It can be obtained by GetDefaultView(..)
Let's say you have a viewmodel flag "IsHidden", stating that it's content does not match the user input:
ICollectionView cv= CollectionViewSource.GetDefaultView(myComboBox.ItemsSource);
// switch filter on
cv.Filter = obj => (obj as myViewModel).IsHidden == false;
// switch off
cv.Filter = null
I have a webapp where I am implementing a list of folders. Whenever a folder is clicked, it contents are shown.
After clicking on various folders, thus displaying their contents, I found out that triggering an event on a folder item, multiple models were responding to the event - models for list item appearing in more than one list were not removed when changing folders.
So, I started using this function to remove the collection of list items in a folder.
this.collection.reset()
my problem was solved but now when I try to persist a model to db, I always get the following error...
A "url" property or function must be specified
any idea why this is being caused by this.collection.reset()???
Most likely, you have an event binding somewhere that calls fetch() when reset event is triggered. Look for any bind('reset', ...) statements in your code.
I have a series of views that are to be displayed depending on the currently selected item in a tree within a parent view. These views are created and registered with the region during the initialization method of the parent view and are being correctly deactivated/activated, therefore giving the effect of swapping in/out the correct view. These views have a single underlying viewmodel as their datacontext, which contains data objects supporting INotifyPropertyChanged.
This solution works if there are no currently outstanding edits in progress within the child view but if there is a edit in progress in a view (i.e. the user has changed the contents of a description but hasn't clicked out of the text box) and that view is deactivated (i.e. the a different tree item is clicked within the parent view, thus causing a de-activation to occur) a NullReferenceException is being thrown in the NotifyPropertyChanged() of the underlying data object attached to the now deactivated view.
What seems to be happening is this:
An edit is started by the user in the child view
The user clicks an item in the tree in the parent view
The controller picks up the change in the selected item in the tree
The current child view is deactivated
The new view is activated
The change from the edit happens to the underlying data object (the set method is getting called)
A change notification event is generated by the data object as a result of this change
A null reference exception is thrown.
Presumably, this change notification event is being sent to the now de-activated view, but the view is not null.
I have not tried this myself, but I believe one solution was to listen for the deactivate event of the view using IActiveAware and cancel any editing.
See if this link helps.
I've created accordion like this:
layout:'accordion',
layoutConfig:{
animate:true
}
then i add elements by add() method, then re-render it with doLayout() and set the activeItem:
navigation_panel.getComponent(1).expand(false);
i call expand() method with false parameter, but it still animates the transition, so it takes setting from main layout and ignore that i sent to expand(). How to solve this problem?
Two things happen when you expand an item in an according panel:
1. The old active item is collapsed
2. The new active item is expanded
The collapsing of the old active item is handled by the accordion layout and occurs during the "beforeexpand" event. Looking at the source code, I see that the accordion layout calls
var ai = this.activeItem;
ai.collapse(this.animate)
So, the animation of the collapse of the old active item is completely determined by the "animate" property of the accordion layout. The animation flag you pass in is ignored for these purposes. I'm guessing that if you look closely, you'll see your collapse is animated while the expand is not.
Because the animate flag is passed through explicitly, I don't see any standard, supported way to override this behavior for a single operation.
In 3.0+, you may call the documented method getLayout() before or after render to get a reference a Container's layout object. You could simply set the layout object's animate property to false while manipulating the panel, then set it back when your done. This is not documented to work but probably will based on the source.