开发者

how do I pass a reference to an object via button_click in WPF/C#

开发者 https://www.devze.com 2023-01-05 21:44 出处:网络
I have two pages in WPF.Page A contains all of my code.Page B is meant to be like a control panel where I click buttons to operate window A.

I have two pages in WPF. Page A contains all of my code. Page B is meant to be like a control panel where I click buttons to operate window A.

The problem I am running into is I want to make function calls from B to A but I am getting a scope error.

In the below code I am getting the error specifically on the axFlash object.

namespace GoogleMapsFlashInWpf

{

public partial class ButtonPage : Page
{
    public ButtonPage()
    {
        InitializeComponent();
    }

    private void ClearMarkersButton(object sender, RoutedEventArgs e)
    {
        StackTrace asdf = new StackTrace();
        Console.WriteLine(asdf.GetFrame(0).GetMethod().Name.ToString() + " called from " + asdf.GetFrame(1).GetMethod().开发者_运维问答Name.ToString());
        XElement call = new XElement("invoke",
                new XAttribute("name", "clearMarkers"),
                new XAttribute("returntype", "xml"));
        try
        {

            axFlash.CallFunction(call.ToString(SaveOptions.DisableFormatting));
        }
        catch (Exception error)
        {
            Console.WriteLine(error.ToString());
        }

    }//end ClearMarkersButton
}

}


The error is right...the axFlash object doesn't exist in the scope of that method. You need to make axFlash an object defined under ButtonPage class. Then, you must make sure that axFlash object is set before you wish to call that function.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号