2012-12-08 37 views
0

如何獲取此CallMethodAction方法InitBlah?目前它不會觸發。我懷疑它的簽名是錯誤的:Silverlight CallMethodAction

<Grid x:Name="LayoutRoot"> 
    <Button x:Name="btnEnter" Content="Enter" HorizontalAlignment="Left" Height="48" Margin="96,88,0,0" VerticalAlignment="Top" Width="144"> 
     <interactivity:Interaction.Triggers> 
      <interactivity:EventTrigger EventName="MouseEnter" SourceName="btnEnter"> 
       <interactions:ChangePropertyAction PropertyName="Visibility" Value="Visible" TargetName="TextBoxTest" /> 
       <interactions:CallMethodAction MethodName="InitBlah" TargetObject="{Binding}"/> 
      </interactivity:EventTrigger> 

      <interactivity:EventTrigger EventName="MouseLeave" SourceName="btnEnter"> 
       <interactions:ChangePropertyAction PropertyName="Visibility" Value="Collapsed" TargetName="TextBoxTest" /> 
      </interactivity:EventTrigger> 
     </interactivity:Interaction.Triggers> 
    </Button> 

    <Grid> 
     <TextBlock Name="TextBoxTest" Width="100" Height="100" Visibility="Collapsed">Hello</TextBlock> 

後面的代碼:

public void InitBlah(object sender, RoutedEventArgs e) 
     { 
      var x = 1; 
     } 

的ChangePropertyAction工作正常:當我將鼠標懸停在該按鈕,文本框彈出打招呼。

enter image description here

回答

0

InitBlah方法的簽名應該適當evets匹配。 試試這個:

public void InitBlah(object sender, MouseEventArgs e) 
{ 
    var x = 1; 
} 
+0

由於梅德..其實這並沒有爲我工作,但奇怪的是在使用工具提示,而不是手動連接最多mouseevents的指出正確的方向我:http://www.silverlightshow.net /items/Using-the-ToolTip-control-in-Silverlight-2.aspx –