2010-06-25 16 views
0

我需要Button.click從另一個類,但不工作pickButton.PerformClick()?爲什麼xbutton.PerformClick()不能在silverlight中工作?

[Category("Özel")] 
[DefaultValue(null)] 
public Button pickButton { get; set; } 


protected override void OnKeyUp(KeyEventArgs e) 
{ 
    base.OnKeyUp(e); 
    if (e.Key == Key.F10) 
    { 
     if (pickButton != null) 
     { 
      //pickButton.PerformClick() ?? 
     } 
    } 
} 

回答

3

PerformClick在Silverlight中不可用。

你爲什麼不提取從pickButton點擊事件代碼,並調用來自兩個地方:

protected override void OnKeyUp(KeyEventArgs e) 
{ 
    base.OnKeyUp(e); 
    if (e.Key == Key.F10) 
    { 
     if (pickButton != null) 
     { 
      DoStuff(); 
     } 
    } 
} 

和:

private void pickButton_OnClick(object sender, RoutedEventArgs e) 
{ 
    DoStuff(); 
} 

顯然DoStuff()就是說明這個概念的佔位符。

2

Silverlight不支持該操作。呼的一下事件直接即

pickButton.pickButton_Click(this, null); 


button2_Click(this, null); 
相關問題