简体   繁体   中英

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.

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 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.

Then you'll be able to call your method like this

ClassA.StaticCloseloadHistory();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM