2010-07-07 52 views
1

我在WPF中有兩個頁面。頁面A包含我所有的代碼。頁面B是爲了像一個控制面板,我點擊按鈕來操作窗口A.如何通過WPF/C中的button_click傳遞對象的引用#

我遇到的問題是我想進行從B到A的函數調用,但我得到一個範圍錯誤。

在下面的代碼中,我特別在axFlash對象上得到了錯誤。

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 
} 

}

+0

什麼是axFlash?你的其他班級在哪裏?你究竟得到了什麼錯誤? – 2010-07-07 20:39:56

+0

您需要提供更多信息。你得到什麼樣的錯誤? axFlash是什麼類型的對象? – sbenderli 2010-07-07 20:40:50

+0

axFlash是一個flash對象。我得到這個錯誤:「錯誤\t 1名稱'axFlash'在當前上下文中不存在」 – Paul 2010-07-07 20:41:51

回答

0

該錯誤是右...的axFlash對象不在於方法的範圍存在。您需要使axFlash成爲ButtonPage類下定義的對象。然後,您必須確保在您希望調用該函數之前設置axFlash對象。

+0

我希望只是調用位於窗口A中的方法。我該怎麼做? – Paul 2010-07-07 20:45:26

+0

爲此,應首先在窗口B中添加窗口A的定義。然後,在窗口B中,在您​​的代碼中,調用Parent.axFlash.CallFunction。 請注意,axFlash必須對外界可見。 – sbenderli 2010-07-07 21:16:44

相關問題