【发布时间】:2011-02-21 22:21:17
【问题描述】:
我有一个 C# WPF 应用程序,每次用户打开一个新文件时,内容都会显示在数据网格中。
public partial class MainWindow : Window
{
public TabControl tc = new TabControl();
public MainWindow()
{
InitializeComponents();
}
private FromFile_click(object sender, RoutedEventArgs e)
{
//gets information from file and then...
if (numberOfFiles == 0)
{
masterGrid.Children.Add(tc);
}
TabItem ti = new TabItem();
tc.Items.Add(ti);
DataGrid dg = new DataGrid();
ti.Content = dg;
dg.Name = "Grid"+ ++numberOfFiles;
dg.ItemSource = data;
}
private otherMethod(object sender, RoutedEventArgs e)
{
}
}
我的问题是,如何在方法“otherMethod”中使用 dg 中的数据?另外,是否可以从方法“otherMethod”更改 dg 的父级?
【问题讨论】: