My problem is that I have a databinded ItemsControl with some data presented in a list and user can scroll up and down.
When adding new items to the list (i.e. user refreshes the list), the scroll position moves according to however many new items there are. Is there a way to keep the scroll position upon adding new items?
Thanks
If you have a look at the TombStone Helper project on Codeplex in the ListBoxTombstoner.cs class [1] you will find code which allows you to get at the underlying ScrollViewer for the listbox and get its VerticalOffset property.
You will then be able to manipulate this property however you want - either adding to it if you want the scroll position to move as you add items, or keep it the same.
[1] http://tombstonehelper.codeplex.com/SourceControl/changeset/view/e737b2a34421#TombstoneHelper%2fListBoxTombstoner.cs
Try to set IsSynchronizedWithCurrentItem="True" on the ListBox
Assuming that all items are of a fixed height you should be able to adjust the the ScrollOffset after the addition-being sure to take the number of added items into consideration.
Related
I am currently developping a slideshow viewer that should be able to display all of its images in a grid like display. However, this display has the following requirements :
It should show all items without having to scroll;
It should be able to handle resizing well (like the Grid control does);
I am using a ListBox, with its ItemPanel set to either WrapPanel or UniformGrid, but they didn't met the requirements : Wrap Panel isn't resizing its items to fill all available space ; UniformGrid gets closer to the desired result, but still leaves an empty space at the end of the last row (ie it should only add a row when it can entirely fill it)
I am therefore looking into a way of setting an UniformGrid so that there's no "blank" left at the end.
As an example, let's say I have three items in my collection, and the actual room to fit them all on one row ; the grid will still creates another row for the third one.
I am also open to solutions for that problem involving other controls, as long as they have a similar behaviour on item resizing and still show all of their items at once.
Thanks
We finally decided to go with a simple wrap with a variable width between items and to just deal with having to scroll if there's too many items.
I have two problems with a ListView I am using.
My ListView is set as ListViewView.View = List and I am adding a few items to it, via ListView.Items.Add(string).
The first one, I notice that for text items that are wider than the width of the ListView itself there is no horizontal scroll bad, and I can't seem to find a way to enable it.
The second is that to select an item I need to select click on part of the item itself, rather than the line the item is in. In other words, if I have an item with a really small length, I can't click anywhere on the line to select it, I have to click on it.
Here is an the code I have an what I am seeing:
listView1.Items.Add("aaaabbbbccccddddffffeeeegggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz");
listView1.Items.Add("a");
As you can see from the image above there are no scroll bars and the length of the text on Index[0] is much wider than the width of the ListView
Likewise on Index[1] where the text is just a single a, to select it I have to click directly on top of the a rather than anywhere else in the line.
Is there a way of fixing these two problems easily?
Also the reason why I'm using a ListView is because I want to add images to the items.
Thanks.
For your second problem just set the FullRowSelect to true in properties or you can do listview1.FullRowSelect = true;
In a checkedlistbox control in C# winforms I can add items into it, however the items will be placed under each other even when the height is smaller than the items combined.
My question is;
Can I "split" the checkedlistbox so you can see everything without having to scroll?
So when the left side is full, it will start on the other half of the checkedlistbox.
What you are looking for is CheckedListBox.MultiColumn property.
I'm looking for a control that can hold a list of text items.
For example:
Item 1
Item 2
Item 3
When I add a new item to this list (Item 4 for example), I want the new item to appear at the bottom of the list, and the other items to shift up 1 position. So in this example, adding Item 4, will mean that Item 1 will disappear from the list.
The reason I have not just gone with a listview is because I want the items to scroll up, like an animated transition if that makes sense?
Is there something out there that can do this, or should I be writing my own control?
EDIT: An example of a web based control:
http://buildinternet.s3.amazonaws.com/projects/totem/index.html
EDIT 2: I'm also not after a horizontal marquee control.
You can do that with a ListBox. It isn't exactly a beautiful solution, but adding to its collection and then either scrolling or setting the selected index to ListBox.Items.Count - 1 works.
[Edit:] Oh right, animated. I believe the scrolling is animated if you set the selected index, but I doubt it will be satisfying if you are going for nice graphics.
I am making a WP7 app which has a Listbox of UserControls. Each UserControl has an ItemsControl and Button(for getting more results). On click of the button the ItemsControl items will be increased by 5 or 10.
Now on clicking on the GetMore button of any of the usercontrols except the first or last, there will be an increase in Scrollable height(Total height of the listbox) of the ListBox but the VerticalOffset(position of scrollbar from top) of the ListBox remains same. Now the problem I am facing is that the Vertical Offset is not absolute but relative to Scrollable Height. So the content being viewed till then will be changed basing on the new value of ScollableHeight.
I want to know the relation between them, so that I can do some math and set the VerticalOffset value.
I have added some dependency properties on VerticalOffset and ScrollableHeight through which I can get the events when any of them is changed. Trying to use ScrollIntoView for readjusting the Vertical Offset
Any suggestions or corrections are highly appreciated.
I am not able to find the calculation. But what can be done is listbox can be replaced by a scrollviewer which has itemsControl inside it. But the disadvantage of this is virtualisation is disabled, so will need to check on this.
But, overall this is going to give a bad experience on using such a UserControl in Listbox. So using templated list box given in WP7 toolkit is an option but it is gonna hang a bit since ListBox is not optimized for multi templated virtualization. So I started showing writing listbox item template in such a way it contains all the possible layouts which will enabled from a condition.