[英]calling a public method from a different class private method
i have a method in Class A (see below) and i would like to run that method based on a selection change of a drop down in Class B. I am not sure how it call that method can someone help me/point me in the right direction. 我在A类中有一个方法(请参见下文),并且我想根据B类中下拉菜单的选择更改来运行该方法。我不确定它如何调用该方法可以有人帮助我/指出我的想法。正确的方向。
public void CloseloadHistory()
{
if (canHistory.Height != 0.0)
{
canHistory.Height = 0;
BitmapImage image = new BitmapImage();
image.BeginInit();
image.UriSource = new Uri("pack://application:,,,/DrScribe.EMR;component/Images/Collapse.png");
image.EndInit();
imgHistory.Source = image;
}
else loadHistory();
}
private void ClassBMethod()
{
ClassA classA = new ClassA();
classA.CloaseLoadHistory();
}
You have to instantiate the class of the method (let us say its ClassA) and just call the Method. 您必须实例化方法的类(让我们说它的ClassA),然后只调用Method。
ClassA a = new ClassA();
a.CloseloadHistory();
If you don't want to instantiate the object containing your method, you can make your method static but only if you're able to make the canHistory variable static as well. 如果您不想实例化包含您的方法的对象,则可以将您的方法设为静态,但前提是您也可以将canHistory变量也设为静态。
Then you'll be able to call your method like this 然后您就可以像这样调用您的方法
ClassA.StaticCloseloadHistory();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.