问题
I'm developing a UWP app that is supposed to be used on PC and Tablets and in a lite version later on mobiles.
On PCs I want to provide data in two columns, on mobile I intend to hide one of them (or I'll create a different page), depending to the user's actions.
Functionalities I need are; databinding to a List<T>
(or anything equal), to filter, sort(not important) and select items, like I did before with the Datagrid.
Values of the selected item should be shown to be edited in two textboxes, so I need something like the selectedItem
property. Also the content is not static since I need to be able to add and delete items.
Is there anything that I can use for this?
I already had in my mind to use two list views, but I guess scrolling will not work properly.
public class Items
{
public Int32 id;
public String name;
public String name2;
}
List<Items> Test = new List<Items>();
回答1:
I need are databinding to a List(or anything equal), to filter, sort(not important) and select items
As far as I know, there’s no build-in DataGrid control in UWP. If you want to show your data as a table, you would have to do it by yourself. For example, you could use ListView and GridView, custom its ItemTemplate to make it look like a DataGrid. It’s a good start with “Guidelines for list view and grid view”.
If you don’t want to do it by yourself, you could think about using some opensource library. You could use Bing to search with this keyword: UWP DataGrid Control
Also the content is not static since I need to be able to add and delete items.
In UWP, you could use “ObservableCollection” instead of “List”, because it has implemented the INotifyPropertyChanged interface, when you add and delete items, it would update UI automatically.
回答2:
Use GridView, it's default behavior is fit as much items in row as possible, so if your 'column' would be 500px wide, just create 1000-1400px wide GridView and you'll have two columns and X rows.
As gridview's ItemsSource use ObservableColletion instead of List, it's able to react on added or deleted items automatically.
来源:https://stackoverflow.com/questions/37962841/is-datagrid-an-alternative-for-uwp