在C#语言中,是否可以使用另一个类中的外部事件列表?
namespace Namespace
{
public partial class win: Window
{
public ExternalEvent ExEvent;
public IList<string> materialList_W { get; set; }
public ThirdWindow()
{
InitializeComponent();
}
private void LoadMaterials2DataGrid(object sender, RoutedEventArgs e)
{
//call the function to store the material list without SP
ExEvent.Raise();
IList<string> materialList = materialList_W;
dataGridExcel.ItemsSource = materialList;
}
public class EventRegisterHandler : IExternalEventHandler
{
public bool EventRegistered { get; set; }
public IList<string> materialList_W { get; set; }
public void Execute(UIApplication app)
{
UIDocument uiDoc = app.ActiveUIDocument;
Document doc = app.ActiveUIDocument.Document;
Revit_Funtion revitFunction = new Revit_Funtion();
List<Material> totalMaterials = revitFunction.StoreMaterials(doc);
IList<string> materialList=new List<string>();
foreach (Material m in totalMaterials )
materialList.Add(m.Name.ToString());
materialList_W = materialList;
}
public string GetName()
{
return "EventRegisterHandler";
}
}
}
}
所以,我在EventRegisterHandler(IList materialList)上获得了一个List。我已将内容存储在materialList_W中。然后我尝试在LoadMaterials2DataGrid()按钮的其他类(win)中打开。
然而这不起作用。
我的问题是在不同的类中没有使用相同的对象。我知道怎么做。问题是从事件处理程序(即IList materialList_W)中检索对象并在另一个类中使用它(即IList materialList = materialList_W;)