我正在创建CRUD应用程序,基本上我想做的是创建datagrid,其中每一行都有自己的按钮以减小一个单元格的值(这是通过Entity Framework从SQL中获取数据)。就像使用数据库的后台代码正在工作,否则我稍后会解决此问题,但是我的问题恰恰是在数据网格中显示按钮的方式。
它显示如下:System.Windows.Controls.Button
。我不知道该如何更改。
我一直在寻找这个问题大约3个小时,但找不到 一个对我有帮助的满意答案。
该类负责数据处理的部分
public Button SubstractByOne = new Button();
public LearnDayAdvenced(LearningDays learnDay)
{
SubstractByOne.Name = "substract";
SubstractByOne.Click += new RoutedEventHandler(Button_click);
}
protected void Button_click(object sender, EventArgs e)
{
SubstractTime();
}
以及负责显示和创建数据的代码。 (我知道我应该重构它,但是如果出现这样的问题)
ICollection<LearnDayAdvenced> learnDayAdvenceds = new List<LearnDayAdvenced>();
foreach (var learningDay in learningDaysAsSource)
{
LearnDayAdvenced advencedLearnDay = new LearnDayAdvenced(learningDay);
learnDayAdvenceds.Add(advencedLearnDay);
}
DataTable learningDataTable = new DataTable("Learn Days");
learningDataTable.Columns.Add(new DataColumn("Subject name", typeof(string)));
learningDataTable.Columns.Add(new DataColumn("time left", typeof(double)));
learningDataTable.Columns.Add(new DataColumn("Substract by 1", typeof(Button)));
foreach (var learnDay in learnDayAdvenceds)
{
learningDataTable.Rows.Add(learnDay.LearnDay.subjectName, learnDay.LearnDay.learningTimeAmount, learnDay.SubstractByOne);
}
this.DataGrid.ItemsSource = learningDataTable.AsDataView();
答案 0 :(得分:0)