WPF control similar to ObjectListView - c#

I'm writing an application using WPF, and I need to make something that looks like this (see image):
What control should I use for this?

If you don’t need the groupings (the “Hire as chef” and “Seek dinner invitation” headings), then DataGrid should get you close. You can bind its ItemsSource to your collection of items, and define custom columns bound to your items’ properties.
For example, you can use a DataGridTextColumn for “Occupation”, DataGridCheckBoxColumn for “Tells Jokes?”, and DataGridTemplateColumn for more complex properties which require a custom DataTemplate to visualize, such as the main “Person” column or “Cooking skill”.
Edi: It appears that the DataGrid does support grouping as well.

You should go for ListView
http://msdn.microsoft.com/en-us/library/ms754027(v=vs.90).aspx

Related

C# WPF Sorting DataGrid on XAML side

I tried using the method documented in this thread:
Pre-sorting a DataGrid in WPF
My issue however is that my datagrid's itemssource is not always the same...it will be bound to different observable collections during the execution of the program. With that, how do I sort the data grid? Is there another way to do this? on the display side....
Thanks
If you are using data binding to set the ItemsSource then just add an IValueConverter (via the Converter property) that converts it to a CollectionView when it's set. If you are using code to set your ItemsSource then just follow their example.
You won't be able to use XAML to populate the SortDescriptions on the CollectionView however, unless you write your own MarkupExtension or an attached property of some sort. These are somewhat advanced topics so please indicate if that is the kind of answer you are looking for.

How to autogenerate columns in UWP XAML GridView or ListView?

In a Windows 10 UWP application I'd like to bind a collection of simple objects to a GridView or ListView and have the GridView or ListView autogenerate the columns based on the properties of the object rather than having to manually declare the columns and {Binding Path=SomePropertyName} on a TextBlock in the XAML.
This doesn't look possible.. is it?
Is there a different type of control other than GridView or ListView that will allow this behaviour?
Note: This is not WPF
TL;DR: This is not possible out of the box with the GridView or ListView controls.
In UWP a GridView is:
A control that displays data items in rows and columns.
The ListView is quite similar but only shows the items stacked in 1 dimension, by default vertical.
The DataGrid control (what this is typically called) is currently (as of SDK build 14393) not available in the default control set. With "some" effort you could write your own control for this behavior.
There are however multiple 3rd party solutions available, just google/bing for UWP DataGrid. Here are some of them:
MyToolkit.Extended NuGet package, more info on their GitHub page.
Libraries that might need a paid subscription/license:
SyncFusion
ComponentOne
Infragistics
You might find even more alternatives.
Can you write it in c# instead of xaml? Maybe it would be possible then, as long as you can access the container (gridview or whatever you use) beyond the constructor of your class. I'm not entirely sure if you can generate a new grid and switch on the fly but you could test it easily.

TreeView with columns

I need a multi columned Treeview for an app I am writing, I was wondering if anyone knew of a free working (in Vs-2010) multi columned Treeview.
There are a number of sample controls to be found around the web:
TreeViewAdv for .Net
TreeView with Columns
ContainerListView and TreeListView
But the all-time favorite is probably the ObjectListView, which provides an expandable, multi-column ListView, along with many other incredibly handy features:
You can use this example here or download this control
Try this Microsof TreeListView WPF control
http://msdn.microsoft.com/en-us/library/vstudio/ms771523%28v=vs.90%29.aspx
You can do an illusion to the user in the user interface.
Drag a listview and drop this over the treeview which was already placed in the form.
Create columns in the listview as you need.
Set the 'HeaderStyle' property to 'Nonclickable' and 'Scrollabe' property to 'False' of the listview.
Set width and location of the listview as it fits to the treeview.

Creating a dynamic grid control

While working in WPF i have the need for a Dynamic Grid. By this i mean a grid that contains only one kind of object, has a template for that object etc. But unlike a similar ItemsControl like a Listbox, i want the grid to be given a Maximum Columns property. This should act as a delimiter which will then calculate the number of rows needed based on the number of objects within the grid. To do this, i thought of inherriting a Grid to make use of its Row and Column properties, but i have a problem... I dont know how to implement an ItemsSource property outside of inherriting the ItemsSource from an ItemsControl...
so my question comes in two parts...
Am i pursuing this the right way? should i be inherriting ItemsControl and trying to re-implement the Grid behavior
if this is the right way to do it, how do i implement an ItemsSource property with its corresponding ItemTemplate
Perhaps a better way would be to use a ListView? Here is an example how to achieve 3-column output: http://kristofmattei.be/2010/03/16/multi-column-listview/
Do you want something like UniformGrid? If you set the Columns property (and don't set the Rows property), it will automatically figure out how many rows to create to hold its items.

Silverlight 3 - Dynamic TabItems in TabControl

I've got an ObservableCollection of POCOs (Plain old CLR Objects) that I want to represent in a tabbed idiom. Prefereably using the MVVM pattern, is there a way to bind the collection of TabItems to the count of my POCO collection?
So, in this case if there are 3 items in my collection, I'd like to see 3 TabItems. Each TabItem would contain the same controls in the same location, each control bound to properties of the appropriate object in the collection.
I'm just looking for an overview of the approach I might use or a link to an example. If you need more info, feel free to ask.
Thanks.
I'd probably create an ObservableColletion with your POCO items in it. You could then bind that ObservableCollection to any of the Silverlight Item Rendering controls. You'll have to modify the default rendering template to create your tabs...but using that method, your tabs will constantly be up to date with the items in the collection without having to put any code in the code behind file.
UPDATE
Here's a link to the Silverlight Forums where somebody built a TabControl using the ItemsControl with sample XAML code:
http://silverlight.net/forums/t/12271.aspx
...just scroll down a bit to see the sample.
One way to do this is to use a value converter (IValueConverter) to return your POCO wrapped in a TabItem. I posted an example here as part of a related question. There is also sample xaml binding and injection of the ViewModel as a parameter to the value converter.
/jhd

Categories