我在MainWindow.xaml中有一个WPF Datagrid,该数据是从另一种形式(AddFixtures.xaml)传递到的。我在AddFixtures.xaml.cs中有一个“ Fixture”类:
public class Fixture
{
public int fixtureID { get; set; }
public int channelID { get; set; }
public string fixtureName { get; set; }
public string position { get; set; }
public string patch { get; set; }
public string mode { get; set; }
public string power { get; set; }
public string direction { get; set; }
public int channelsUsed { get; set; }
}
此(MainWindow.xaml.cs)收到的内容:
fixtureData.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(
delegate (object sender,System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.action == System.Collections.Specialized.NotifyCollectionChangedaction.Add)
{
FixtureView.Items.Add(fixtureData);
}
}
);
基本上,我将信息输入另一种形式并按一个按钮,然后将数据添加到DataGrid。我有一些需要根据数量增加的信息。我已经将此增加,但是在DataGrid中,它始终显示输入的第一个值。当我单击(AddFixtures.xaml.cs)中的按钮时,将执行以下代码:
private void BtnAddFixture_Click(object sender,RoutedEventArgs e)
{
int quantity = Int32.Parse(txtQuantity.Text);
for (int i = 0; i < quantity; i++)
{
MainWindow.fixtureData.Add(new Fixture()
{
fixtureID = Int32.Parse(txtFixtureID.Text),channelID = Int32.Parse(txtChannelID.Text),fixtureName = cbxFixture.Text,position = cbxPosition.Text,patch = cbxUniverse.Text + "." + txtChannel.Text,mode = cbxMode.Text,power = cbxSocca.Text + "." + cbxWay.Text,direction = "Forwards",channelsUsed = Int32.Parse(lblChannels.Content.ToString())
});
fixtureID++;
channelID++;
txtFixtureID.Text = fixtureID.ToString();
txtChannel.Text = channelID.ToString();
}
}
任何帮助将不胜感激