I have an ObservableCollection where I move the items by
oc.Move(oldIndex, newIndex);
This ObservableCollection is used as ItemsSource for a ListView. Now I want the ReorderThemeTransition or RepositionThemeTransition, but unfortunately there seems to be a full reset. If I add or delete items, everything is fine (a scaling animation, like it should).
I checked the CollectionChanged Action, but there I get only Moves (as supposed to, no Reset or anything) and I also tried to Move only one element at a time, but still the full list flashes and is reordered.
I tried to add ReorderThemeTransition (and all other transitions) to ListView.Transitions, ListView.ItemContainerTransitions and to the ItemsPanel, which is a ItemsWrapGrid as ItemsWrapGrid.ChildrenTransition.
Any ideas, what else I could try?
Related
I have an ObservableCollection which is bound to some ItemsControl (FlipView) as its ItemsSource. I was having an issue with the scrolling on a touch device where the entire FlipView would disappear as soon as user touches the screen and it would reappear when the finger is removed from the screen. So to fix that, I had to work around it by clearing the collection whenever I had to refresh it (instead of re-instantiating it). I noticed that the same issue (with touch) was occurring when I used .Clear() in order to clear the collection but when I looped through the collection and removed the items one-by-one the issue was resolved.
So, I am still not clear as to what is the difference b/w these two ways of clearing the ObservableCollection?
If I remember correctly internally the ObservableCollection maintains a IList which is assigned an instance of List. The ObservableCollection.Clear method eventually calls Clear on the interal list and that List.Clear method then uses Array.Clear to clear the items.
I have a simple combobox bound to a List where A has a property Key and a property Value.
The combobox binds fine and works except for one flaw. It has a large empty space at the bottom where there are no items (i.e they don't get highlighted on hover or any such thing, there are no extra items, it is just that there is an empty space). How can I get rid of it?
http://i.stack.imgur.com/2yN9r.jpg
This is most-probably because of the template of the ComboBox under your current theme. Try changing Windows theme to Aero or Luna (seems like now you have it set to Classic).
If that's the issue, then there's a way to "fix" it by using a custom template, but then you break consistency from user's point of view. You'd need to take it into consideration.
you need to change the Template of combobox and reset the popup height acordingly. check below.
http://msdn.microsoft.com/en-in/library/ms752094%28v=vs.85%29.aspx
Search for popup under the tempalte and add the minheight=0 into it.
In my ComboBox ItemsSource="{Binding MyItems..., if MyItems is a List, it will leave extra space. if MyItems is an ObservableCollection, the extra space goes away. This may due to a Microsoft bug that ItemsSource was not properly notify by MyItems change when it is a List object.
I have this idea in my head for an equalizer-like control, but I'd like to be able to do multiselection of the various thumbs and move them all at once. I thought of using a listbox and using the selection property it has but I haven't quite worked out how I'd be able to pass that down into the sliders and move them all in unison. Does anyone have any good ideas or has seen something like this done before?
Presumably you have some control that the user interacts with. One idea would be to create adorners around those controls to show "selected" state. Listen in on the mouse clicks for each of those controls and test the Ctrl modifier (Ctrl and/or shift, both are commonly used for multiple selection). Toggle the selected state of each of them which you'll store in a separate collection (an array perhaps).
When you detect movement on one of these controls, check to see if it's selected. If it is, move all the others.
maybe you can use the SelectedItems property of the Listbox in MultiExtended selection mode.
you bind it to an Observablecollection
then you check the slider's valueChanged event and in the eventhandler you get the difference and increment all the sliders' values in the collection.
now when you select and drag a slider's thumb it will affect other selected sliders.
(minor question: are you using MVVM?)
We have a ListBox that has a number of items. Items are inserted into the ListBox via an ObservableCollection. Some of these items can be edited right in the ListBox. However, if an item is added at an index < the edited item's index, the entire content of the ListBox moves down.
What we'd like to do is the following: if an item is in edit mode, we'd like to freeze its position on the screen. It is fine if items are added to the collection and the UI around the item changes. But the position of the item should remain constant on the screen.
The only thing I've been able to do so far is attach to the ScrollChanged event and, at most, use either BringIntoView or ScrollIntoView methods to ensure that the item is always displayed somewhere in the UI, but I am unable to lock down its position.
Has anyone done something like this and help out?
I think the following would solve your problem:
When entering edit mode, keep a reference to the object you're editing, its index in listbox and the ScrollViewer's HorizontalOffset.
In a handler to the ObservableCollection.CollectionChanged event find the new index of the object you editing, if the index changed, swap the edited item with the one now taking it's place (or some other logic if you want to keep a certain order). Then if the ScrollViewer.HorizontalOffset changed, move it back to the said offset.
This will make sure the item you're editing will always stay in the exact same place in the list and in the UI.
Hope this help you out.
You could always force items to be added to the end of your collection. Otherwise, I think you are on the right track with scrolling the ScrollViewer. When entering 'edit mode', track the current horizontal offset.
ScrollViewer sv = listBox.GetScrollViewer();
double indexPos = sv.HorizontalOffset;
However, I think you would be better off attaching to the ObservableCollection.CollectionChanged event. When the event fires, check if the new value was inserted above your 'edit mode' item. If it is, then run the following code.
ScrollViewer sv = listBox.GetScrollViewer();
sv.ScrollToHorizontalOffset(indexPos+1); // This will obviously require an offset
Is the problem that you simply don't want it moving? Or is the problem that you have referenced said item by its index number and the change in index causes other problems when you apply the changes (like applying them to the item that is now at the previous index)?
If the problem is that a change of index causes problems in code, then I would stop using the index and instead get a reference to the object. Later you can always get the index of the item if you find you need it.
Would it be feasible to switch to a ListView, and use EnsureVisible?
If freezing the rest of the listbox is a viable option. Such that items which are added don't appear until after the edit has been completed or escaped then you could try using BeginUpdate and EndUpdate to stop the ListBox from being repainted. I'm not sure how that would effect your editing process though.
I have WPF listview bound to collection of objects. Objects are continuously added in to collection from remote server and same is reflecting in to listview. Now we have requirement that we should be able to freeze listview for some time,
That is objects should still get added in to collection but should not appear in listview till we unfreeze it ( we have button to freeze and unfreeze) . What is the best way to do it, when listview is bound to collection ? How to unbind collection and rebind it ? and Will i still able to filter and sort when collection is unbound from listview ? Waiting for answer please reply
Regards
Sandeep
You can just break the binding. In your freeze button handler say:
listView = _list
Which will freeze it at that point. Then in your unfreeze handler set the binding back up:
listView.SetBinding(ListView.ItemsSourceProperty, New Binding("_list"))
I hope this helps.
You should just stop updating the collection when the list is frozen, if you must keep adding to the collection even when the list is frozen (if the same collection is used somewhere else that shouldn't be frozen) then consider having two collections, one always updated and the other one bound to the listview.
What is the list type you are using as the data-source? Can you use BindingList<T>? If so, this has a settable RaiseListChangedEvents property, allowing you to turn off notifications. This will probably get very messy re your last points, though (sort/filter).
Personally, I'd work with 2 lists - the bound one, and the one that the server is updating. When paused, simply stop pumping data between the two. This should leave the paused view free for sorting / filtering etc.