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.
Related
I need to build a custom items control in WPF, where the user can drag/drop the items. Normally I would just maintain a list of view models and use a data template to define how the items should be displayed (in this case, a button). But I am concerned that this will make the drag/drop difficult as the ItemsSource objects will be view model objects , not the actual button.
My other potential approach is when an object is added to the ItemsSource, create a button in c# and add it manually, that way I can access the button directly to do drag/drop.
What would your advice be?
I have solved my issue. I found a way to get the control being render from the data template
I have a treeview right now with a templateselector. Basically each tree node on the root is a "category" of some type of data and each child node under those are displayed in a specific way (via the template selector).
This allows me to show different data in a single control easily just using binding. My problem is that it's not working out so well visually. I would like to have a grid style (ListView.GridView) under each root node.
I was looking at ListView grouping but is it possible to define different columns for each group? Since I doubt that is possible, what are some options? I would like to allow the user to expand and collapse the groups just like a treeview but see a GridView under each node with scroll bars, etc.
I don't think that ListView supports different headers in groups. It's just grouping of rows. Looks like you're going to have to create a new ListView under each tree node. You might try a data grid. In WinForms you can bind to multiple tables and the grid will group by table which can be expanded and collapsed which would in effect show different columns. If you're using MVVM (I assume some collection or hierarchy model) I have no idea how you'd accomplish that with a data grid.
You may achieve what you want relatively simple if you adopt the MVVM architecture.
Each node on the tree is of a certain type (ViewModel). Each data type would be bind to a specific View. Each View can be a ListView with any columns you want.
I recommend you read about MVVM and adopt it in order to achievewhat you need. I found that the adoption of MVVM leads to applications with a much cleaner architecture and code.
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/
I want to create my own expandable/collapsable tree-like UserControl, which nodes are the Border elements with any content. And this control should have the single SelectedItem. When I select one of the nodes I want to see details information about selected item.
I've done the control's presentation and a piece of logic:
I can see all the tree of elements, collaps any node(s), select one of them and see details. But I can't do bidirectional binding. I.e. I want to have an opportunity to change fields in details panel and immidiately see changes in the tree-control.
Help me please either call force update (rebind data) of the control (just give a tip how to perform this) or give an advise how to create my own List-like UserControl.
I tried to make my control inherit from some ListBox class but I couldn't.
PS. Sorry for my bad English...
Use the TreeView control.
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.