小编fra*_*mps的帖子

WPF组合框数据绑定所选项

我正在尝试将a数据绑定ComboBox到列表中strings.到目前为止,我有以下内容:

在我看来,我有:

<ComboBox Height="23" 
          HorizontalAlignment="Left" 
          Margin="133,180,0,0" 
          Name="comboBox1" 
          ItemsSource="{Binding Hours}" 
          VerticalAlignment="Top" 
          Width="38" />
Run Code Online (Sandbox Code Playgroud)

在我的ViewModel中,我有:

private List<string> tripTimeHours = new List<string>();
private List<string> tripTimeMinutes = new List<string>();

public CreateTripViewModel()
{
    TripName = new DataWrapper<string>(this, tripNameChangeArgs);
    TripName.IsEditable = true;
    setObjects();
    CreateTripFiredCommand = new SimpleCommand<object, EventToCommandArgs>(ExecuteCreateTripCommand);
}

private void setObjects()
{
    for (int i = 0; i < 24; i++)
    {
        tripTimeHours.Add(i.ToString());
    }

    for (int i = 0; i < 60; i++)
    {
        tripTimeMinutes.Add(i.ToString());
    }
}

public List<string> Hours
{ …
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf mvvm

4
推荐指数
1
解决办法
2万
查看次数

如何使用WPF和MVVM从数据库加载DataGrid数据?

我是WPF和MVVM的新手,所以如果这个查询非常简单,我会提前道歉.我在网上搜索过,但却找不到符合我要求的东西.为什么我在这里!

我目前正在尝试使用LINQ实现从数据库查询的数据表.这是我运行的查询:

DataContext connection = new DataContext();

    var getTripInformation = from m in connection.tblTrips
                where m.TripDate > DateTime.Today
                select new { m.TripID, m.TripName, m.TripDate, m.ClosingDate, m.PricePerAdult, m.PricePerChild, m.Status };
Run Code Online (Sandbox Code Playgroud)

这填补了我的变量与我期望的相关信息.

现在,我想要做的是使用DataGrid在我的视图中显示它.任何人都可以帮我这个吗?

wpf mvvm wpfdatagrid c#-4.0

3
推荐指数
1
解决办法
3411
查看次数

标签 统计

mvvm ×2

wpf ×2

c# ×1

c#-4.0 ×1

data-binding ×1

wpfdatagrid ×1