I have the Property
ObservableCollection<List<AuditViewModel>>Audits
and i want to represent it in a xaml as a grid where the observableCollection represent the rows and the List represent the columns.
any idea how can i do it?
Thanks, Lin.
You can create a ListBox control and bind it's ItemSource to Audits. That gets you the rows. Then you could create an itemtemplate for the listview that displays all the values of the AuditViewModel. That ItemTemplate will be bound to AuditViewModel. Should just be "{Binding}".
Related
I have a listbox in which I have stored domain objects. These objects have a property price. Now I would like to bind the content of a textblock to the sum of the priceproperties of the items in my listbox. What is the simpelest way to do this? I'm not working with a MVVM.
Sean
I have a wpf application using mvvm. I am trying to bind my datatable to a combobox that has a datatemplate of 2 textblocks. How do I specify the binding on these text blocks to bind to datarowview.item["columnname"]
In short, what I am trying to achieve is to bind 2 columns of my datatable to a multicolumn combo box
It turns our that you can simply bind to the column names just like how you blind to an object's public property. WPF is smart enough to figure it out.
Does anybody saw control like this somewhere?
I need to make such control to represent hierarchical data (it should be generic very likely, i.e. data binding, templates support).
Something like combination of ComboBox and MenuItem’s.
I think I will redefine the combobox itemtemplate with some hierarchicaldatatemplate along with popup class.
Just put ComboBoxes on a form and bind the ItemsSource to the top level collection.
Then bind the DataContext of the next ComboBox to the SelectedItem of the box on the left and bind its ItemSource to the collection of items.
You know how to bind to SelectedItem?
E.G.
Column1
Public String Name
Public List Column2s
So you bind the first combox to List with he displaymemberpath = name
Then on the second combobox you bind to Column1 selecteditem with items source path of Column2s
The trick is to build up the Lists within the Lists within the Lists
All right, I made it by custom control inherited from ComboBox, custom ComboBoxItem inherited from HeaderedItemsControl and using HierarchicalDataTemplate.
I've got a TabControl in my WPF application. The TabControl's ItemsSource is bound to an ObservableCollction of view objects. It uses a DataTemplate to populate the visual tree for the tabs from the Items in the collection.
I need to be select the current tabs in the conde-behind in response to actions the user takes on another screen in the application. When I iterate over the items in the TabControl's Items collection, I get the instances of my view models.
How do I access the actual TabItems and iterate over them, then select the one I want?
Tony
If you're using a MVVM approach you should bind your TabControl's SelectedItem property to the same object that holds your ObservableCollection of TabItems (the ViewModel). When you need to change the current tab set the SelectedItem property to the correct TabItem in the ObservableCollection.
I have a WPF user control that will dynamically have any number of GridViews. Each is essentially the exact same except for the ItemsSource. Therefore each have the same columns and the same RowDetailsTemplate. To be specific what I am actually doing is settings the columns to the bound values and then setting the RowDetailsTemplate to the data template.
What is the best approach to essentially define the GridView once and copy it to all the others. I have tried XamlWriter.Save with the GridView in the resources, but the columns and RowDetailsTemplate are not saved. I have also tried a style, but the columns property is not settable.
Maybe I did something wrong with the two approaches.
Use an ItemsControl with ItemTemplate. The DataTemplate used for the Itemtemplate should contain the GridView XAML with all the column definitions. Next bind the ItemsControl's ItemSource to a collection of whatever data object you want the GridViews to use as ItemSource.