2011-11-11 5 views
1

그래서 나는 즉시 (RegularPolygon 정확히) 컨트롤을 만들려고 해요 및 이벤트 이벤트를 기반으로 EventTrigger 컨트롤로 2 PlaySoundActions 추가하고 싶습니다. '시스템 에 'Microsoft.Expression.Interactivity.Media.PlaySoundAction '에서 변환 할 수 없습니다 : 각 행은이 인수 1SoundActions가있는 EventTrigger를 코드 뒤에 추가하는 방법은 무엇입니까?

오류와 같은 오류가

EventTrigger trigger = new EventTrigger(); 
PlaySoundAction correct = new PlaySoundAction(); 
PlaySoundAction incorrect = new PlaySoundAction(); 
correct.Source = new Uri("/Sounds/Correct.mp3"); 
correct.Volume = 0.5; 
incorrect.Source = new Uri("/Sounds/Incorrect.mp3"); 
incorrect.Volume = 0.5; 

trigger.Actions.Add(correct); // this line doesn't work 
trigger.Actions.Add(incorrect); // this also doesn't work 
shape.Triggers.Add(trigger); 

: 현재 나는 다음과 같은 코드가 있습니다 .Windows.TriggerAction '

PlaySoundAction 개체를 어떤 형식으로 캐스트해야할지 모르겠습니다. XAML에서이 컨트롤을 즉시 만들고 있기 때문에이 작업을 수행하고 싶지 않습니다.

또한 RegularPolygon의 스타일을 만들어서 PlaySoundAction을 사용하여 EventTrigger를 만들려고했으나 프로그래밍 방식으로 컨트롤의 스타일을 설정해도이 논리가 컨트롤에 추가되지 않았습니다.

<Application.Resources> 
     <ResourceDictionary> 
      <Style TargetType="es:RegularPolygon" x:Key="Default"> 
       <i:Interaction.Triggers> 
        <i:EventTrigger EventName="Tap"> 
         <eim:PlaySoundAction Source="/Sounds/Incorrect.mp3" Volume="0.5" /> 
         <eim:PlaySoundAction Source="/Sounds/Correct.mp3" Volume="0.5" /> 
        </i:EventTrigger> 
       </i:Interaction.Triggers> 
      </Style> 
     </ResourceDictionary> 
</Application.Resources> 

뒤에 코드에서 EventTrigger/PlaySoundAction를 추가하거나 제어가이 EventTrigger/PlaySoundAction을 가지고에서 상속 할 수있는 스타일을 만들 수있는 방법이 있나요?

+0

문서는 어쩌면 PlaySoundAction은 필요하지 않습니다 조치 BeginStoryboard 개체의 컬렉션 말한다? http://msdn.microsoft.com/en-us/library/system.windows.eventtrigger.actions(v=VS.95).aspx –

답변

5

아마도 코드에서 System.Windows.Interactivity.EventTrigger 대신 System.Windows.EventTrigger를 사용하려고한다는 것을 알면 도움이 될 것입니다. 내가 명시 적으로 지정하는 경우 - 나는 일을 가지고 :

System.Windows.Interactivity.EventTrigger trigger = 
    new System.Windows.Interactivity.EventTrigger(); 
trigger.EventName = "MouseLeftButtonDown"; 
PlaySoundAction correct = new PlaySoundAction(); 
correct.Source = new Uri("/Sample.wma", UriKind.Relative); 
correct.Volume = 1.0; 
trigger.Actions.Add(correct); 
trigger.Attach(myTextBlock); 

당신은 당신의 통제도 도청 할 수 있는지 확인해야합니다 - IsHitTestVisible false로 설정할 수 없습니다 수 있으며 채우기 브러시 세트를 가질 필요가있다. 사용자 지정 컨트롤이 무엇인지 잘 모릅니다.

이 내 XAML입니다 :

<Grid 
    x:Name="ContentPanel" 
    Background="LightCoral" 
    Tap="ContentPanel_Tap" 
    Grid.Row="1" 
    Margin="12,0,12,0" > 
    <StackPanel> 
     <TextBlock 
      Text="XAML Test"> 
      <i:Interaction.Triggers> 
       <i:EventTrigger 
        EventName="MouseLeftButtonDown"> 
        <eim:PlaySoundAction 
         Source="/Balloon.wav" 
         Volume="1" /> 
       </i:EventTrigger> 
      </i:Interaction.Triggers> 
     </TextBlock> 
     <TextBlock 
      Margin="0,100,0,0" 
      x:Name="myTextBlock" 
      Text="Coded Test" /> 
    </StackPanel> 
</Grid> 
+0

흠, 일단 기회가 생기면 그 점을 확인해야 할 것입니다. – ShelbyZ

+0

이렇게하면 EventTrigger를 충분히 추가 할 수 있지만 트리거를 실행하는 것은 다른 문제로 보입니다. – ShelbyZ

+0

여기에 내 솔루션을 넣어 : http://dl.dropbox.com/u/1192076/PlaySoundActionTest.zip 또한 내 대답에 XAML을 추가합니다. –

관련 문제