I am currently working on a WPF project in C# using MVVM. In this project I have a list box that loads a user control for each row of data in my items source.
The user control that gets added for each item in my collection also contains a list box that is filled from a database. This second list box often grows and therefore makes each item larger than the view of the first listbox.
My question is, how to I make my listbox have smooth scrolling. Right now it jumps from the top of one item the the top of the next. Since each item is bigger than the view of the listbox I need to be able to scroll without jumping from the top of each item to the next.
I have used a scrollview to achieve this but the list box then intercepts the mouse wheel event and will not allow me to scroll without hovering over the scroll bar.
Is there a better way to do this?
UPDATE:
I can get smooth scrolling using the scrollview control but I cannot scroll while my mouse is inside the scrollview. I have to have my mouse over the scrollbar in order to scroll.
It is like something is intercepting my mousewheel event.
I was able to achieve what I was trying to do by using a ItemsControl rather than the ListBox. It loaded just like the ListBox control and pulled all of my data into it and let the ScrollView handle the scrolling. It did not intercept the mousewheel even like the listbox did.
If you do not need to be able to select an item, I highly recommend using the ItemsControl.
You can set on the Listbox the following Property ScrollViewer.CanContentScroll="False".
Related
I have a string array. Each array element has some content. I need a horizontal scroll bar or anything similar below the window. On clicking next or previous button, array elements needs to be displayed in a textbox accordingly. Something like paging. But I am unable to find any such control. I need to perform this in WPF and MVVM pattern.
Else i'll have to put two buttons and implement the functionality on its click events. But I would not get the scroll bar effect.
Any help would be much appreciated!
I got a treeview with a bunch of nodes where more gets added over time. When I add a new node to the treeview, I need to make sure that the very bottom most node is visible.
I tried using the ItemContainerGenerator to select the last item and bring it into view. But it doesn't work for me.
How can I make my treeview scroll to the very last item?
If you are working with TreeViewItem in code, I think you can use treeViewItem.BringIntoView() which should cause the scrollable area the item is in to scroll so that it is visible.
Edits
Examples
view.SchemaUpdateGrid.ScrollIntoView(e.UserState);
The above like is from a BackgroundWorker.ProgressChanged event handler. e.UserState contains the currently working object (custom class), not a grid row. The grid automatically translates the object into the item.
I have a ScrollViewer and a ListBox inside it which is bound to an ObservableCollection in the view model. The ScrollViewer is maximized to take up all available space of the parent container. I'm finding that when the collection is modified and ends up producing more ListBoxItems than can fit in the viewable area of the ScrollViewer, the ScrollViewer scrolls down to show the last item in the ListBox. How do I prevent the ScrollViewer from scrolling when the child ListBox's items are updated?
I would like the scroll position to stay intact whenever the collection in the view model is updated.
Thanks in advance!
You are going to have to manage this yourself. The ListBox has a ScrollIntoView method that allows you to scroll to a specific location:
http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.scrollintoview(v=VS.95).aspx
Determining the items that are currently visible, if you need this, is not so easy. See the ItemsControlExtensions that I wrote as part of the WP7Contrib project:
http://wp7contrib.codeplex.com/SourceControl/changeset/view/67473#1475881
This has a GetItemsInView extensions method that will provide the list of visible items.
I implemented a drag and drop of an image from a Grid to another Grid using built-in MouseDragElementBehavior class. Then I needed to use a bit more complex layout for the source items so used ListBox and ItemTemplate instead.
The problem is now when dragging an item from the ListBox it is only visible when above the ListBox. How do I make it always visible and following mouse cursor anywhere while being dragged?
I suggest that instead of writing your own implementation using the Blend SDK, that you use the Silverlight Toolkit ListBoxDragDropTarget control.
The reason the item disappears in your element is that the MouseDragElementBehaviour is simplistically applying a render transform to affect the movement. However the ListView places its item panel inside a ScrollViewer which clips its content to its viewport.
I have a surfaceListBox that contains many items.
when I put the SelectionMode to multiple , every thing is fine and I click on an item to add it to the selectionItems,
But I want to get the same behaviour but not with clicking on the items but when the touch is moving over the item ,
Here is some details of the manipulation I want to add:
if the touch is moving over a surfacelistboxitem , this item is added to the selectedItems .
Thanks for your help
SurfaceListBox doesn't support this because it needs to treat moving fingers as scrolling.
If you don't need the ability to scroll, you can ditch SurfaceListBox and instead use a StackPanel filled with SurfaceToggleButton elements. On those toggle buttons, set ClickMode=Hover so that they will toggle just by moving your finger over them.
-Robert (former PM for the Surface controls)