I'm interested in creating an ItemsControl for Silverlight that "loops" the items. When the user scrolls to the end of the list the ItemsControl should then show the first item(s) in the list. If the user scrolls above the first item in the list the ItemsControl should show the last item(s) in the list. It probably makes sense here for the ItemsControl to hold more items than it contains. What's a good way to go about creating this control? I'm planning to data bind the ItemsSource property so a custom collection could also work.
Turn to the good doctor for help: http://drwpf.com/blog/2009/08/05/itemscontrol-n-is-for-natural-user-interface/
Related
I have a tree view that displays a structure of agenda items. The tree structure is merely for ui and usability purposes. The tree view is “flattened” into a linear list of agenda items. When an item is selected in the tree view, I would like to scroll the corresponding linear list item to the top of the listview.
The items in the listview are custom user controls.
I would like to use an attached behavior since I need to stay within MVVM. I have manly to issues. I need to be able to inject an index into the view and trigger the scroll itself by a command.
Any ideas?
Kind regards
This approach seem feasible but Im not getting how to pass an index to a behavior. https://marcominerva.wordpress.com/2014/09/30/scrolltobottom-behavior-for-listview-in-mvvm-based-universal-windows-apps/
This StackOverflow question should help you:
mvvm how to make a list view auto scroll to a new item in a list view
You shouldn't need to deal with an Index if you're using MVVM, just use the selected item instead. Ideally, your TreeView and ListView should be binding to the same items.
within WPF I have created a ListView which displays a list of messages in chronological order using a custom ItemsPanel class which uses the time of the messages to correct space them apart when laying out the items;
Is there an easy way to go one step further and add 'other drawing items', for example a timeline (line, ticks and text), to the background of the ListView which scrolls with it? What's the best approach?
Thanks for your comments, but my solution was to add an ItemsControl which binds to a Timeline collection of integers (one every 100ms) that's sits on top of the ListView (and scrolls with it) which simply has two lines it the ItemTemplate to get the following result:
ListView with added timeline markings
I have a big list (~10000 items) inside a ComboBox, that uses the VirtualizingStackPanel class. The scrolling performance is good, anyway I like to know how to identify the top item shown in the GUI - which is, not necessarily the one with index zero, but the one that is on top of the current scrolled item list. ? Thank you.
I use the FrameworkElement.IsVisible property. Using the method at the link below, you can also check to see if an element is partially visible(which would be useful in your case):
In WPF, how can I determine whether a control is visible to the user?
You could (by using a background thread or by doing a computation when the user scrolls in the combobox), check the items in the ComboBox to see if their FrameworkElement.IsVisible property were set to true. If so, you update that elements IsVisible property in its ViewModel. Now you have a collection in your ViewModel of items that are marked visible or not(and that are constantly updated concerning the visibility of the CoboBox item that it represents). Now you can find which is the first using .First(x=>x.IsVisible==true) on the collection of items.
I have a ListBox in a Silverlight Application. I'm trying to make an editable listbox, so I use an ItemTemplate to have the controls i need in each item, like a textBox and buttons, and its working fine.
I'd like to have a line at the end of the Listbox with a button to add new items. Since this item won't be related to any of my domain classes, I'm using a plain object as a 'Filler', and then I have code that identify this item to show the button correctly.
myListBox.Items.add(new object());
The problem is that I want this "new Record" item to be kept always at the end of listbox, so when I need to insert a new domain record, i use this code:
myListBox.Items.Insert(myListBox.Items.Count - 1, domainItem);
When I debug the myListBox.Items collections, it is in the right order, with the "add new" button at the end, but the listbox is displaying this button at the beggining. Why are my items beeing displayed in a different order than the Items collection?
Unless there is a specific reason, instead of trying to put the button into the listbox collection itself you would be best to create a new control with the button outside and below the listbox. You can always style the button to look as though it's within the listbox if required.
Is there a reason why you are not using a datagrid because it would remove all your ordering problems and it would allow you to edit the entries.
The datagrid is bound to an ObservableCollection which automatically connects your editable fields to the GUI.
Cheers,
I've got a list of things that I want the user to easily edit the order of. Right now I'm binding them to a ListBox with a custom ItemTemplate. Within that template I have an UP & DOWN button. My goal was to move the item up/down based on the button clicked.
However I'm having trouble associating the button's click event with the actual item in the list. I've seen some folks setup a drag/drop for ordering items but that that would be too complex for this app (it's target user base =1, just me).
I assume this is possible with a ListBox. Maybe someone has a beter idea on how to implement this? It's not a huge set of data... less than 25 items.
The DataContext of the button (of the entire template, thus inherited by the button) is the item itself. Simply cast it to your desired type.