如何为Win8 App Store构建自己的DataGrid?

时间:2013-08-19 19:09:41

标签: windows-8 windows-applications

对于我的Win8应用商店,我有一个项目列表,我希望在类似于表格的控件中显示。让我们说对象Item包含条形码,价格和金额(都是双重类型)。我想为这个对象的每个prop呈现一个包含不同列的表。我还想在LayoutAwarePage中呈现此表。有任何想法吗?

1 个答案:

答案 0 :(得分:0)

您可以从这里开始:How to get a data grid like UI for a collection of Items?

MyToolkit - DataGrid

MyToolkit DataGrid的用法

<controls:DataGrid x:Name="dg">
    <controls:DataGrid.Columns>
        <controls:DataGridTextColumn Width="200" Binding="{Binding FirstName}"  />
        <controls:DataGridTextColumn Width="200" Binding="{Binding LastName}" />
    </controls:DataGrid.Columns>
</controls:DataGrid>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    ObservableCollection<viewModel> People = new ObservableCollection<viewModel>
    {
        new viewModel("fname", "lname"),
        new viewModel("fname", "lname"),
        new viewModel("fname", "lname"),
        new viewModel("fname", "lname")
    };

    dg.ItemsSource = People;
}

public class viewModel
{
    public viewModel(string firstName, string lastName)
    {
        FirstName = firstName;
        LastName = lastName;
    }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}