I'm having a problem with a TreeView in WPF C#.
I have a TreeView with two TreeViewItems defined in XAML.
On the second TreeViewItem, I have a list of items defined by a binding.
When the list is too long, a vertical scrollbar appears and allows the entire TreeView to scroll.
But the two TreeViewItems must stay at the same place, so I'd like the content of the second to scroll instead, rather than the entire TreeView.
Left : what I get, and the two first items are scrolled out; Right what I'd like, with the two first items staying at the same spot. (The scrollbar is the red zone).
I look forward to hearing from you guys, and thanks in advance,
Raekh.
EDIT :
Found a solution : I removed the two treeviewitems and used a treeview with a item source obtained by binding, so the treeview starts after the treeviewitems and is scrolled properly.
Related
I have a Window with a WrapPanel containing a variable number of custom items.
By clicking on an item I need to display a panel containing some information about the item selected.
While displaying this panel I'd like the WrapPanel to fill all the available space like in the picture below.
The best I could come up with was to create a UserControl with a Grid with two row, each one containing a WrapPanel.
When the information panel is collapsed I would display only the first WrapPanel which will contains all the items.
While the information panel is visible, I would show both WrapPanels, moving some of the items from the first WrapPanel to the second.
Honestly though, I don't really like it and I was wondering if there was a better solution.
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 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".
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 have to change Listbox's control templated in a way that it can look like below image
alt text http://www.freeimagehosting.net/uploads/05598e4d35.png
i have added togglebutton in listboxdatatemplate...
have one stackpanel in listbox style template...
so structure is like
border - stackpanel - grid - itemcontainer[boder-togglerbutton]
now to make first and last item curved... what are the ways...
if i make stackpanel border curved... when firstitem is selected and its background is changed... it shows a square inside outer border... so i am not able to get look showed below...
any idea?? how to get design done in the way with listbox tht can be showed like image above...
in image 1,3 and 4 items are selected and others are in normal mode...
-thanks in advance
I did it with a listbox in Blend inside of the ItemTemplate by creating a leftBorder and a right Border that are in the same space. The leftBorder is defined with cornerRadius 10,0,0,10 and the right with cornerRadius 0,10,10,0. I then set them both to opacity 0 (you can use visibility if you prefer) and set a ChangePropertyAction on both of thier loaded events conditional on the first and last item in your list.
That is the bad part, I did need to do it conditional on the items in your list but you could define another property and set that to first and last or create multiple templates that you set if there are no more items in the list from the control (not in the template).
If you think this may be interesting to you, let me know and I will post on my blog as well as try to make a couple of adjustments for your situation. I am not sure how to upload a project to here.