2014-04-07 2 views
0

저는 C# 및 xaml 프로그래밍의 새로운 기능입니다. 필자는 Microsoft Kinect 용 KinectExplorer-WPF 솔루션을 수정하여 내 용도로 유용하게 사용하기 시작했습니다. Kinect 창을 수정하여 Kinect 앞에 서있는 사람이 도달 할 수있는 위치를 나타내는 일련의 이미지를 표시하는 새 패널을 추가합니다. 이 난 KinectWindow.xaml 추가 한 코드이다KinectExplorer-WPF 솔루션에서 이벤트를 계속 트리거합니다.

<StackPanel Orientation="Vertical" Grid.Row="1" Grid.RowSpan="2" Margin="0,10" HorizontalAlignment="Center" Width="400" > 
     <Grid Name="ExerciseViewerHost" Width="398" Height="645" Margin="0,0,0,0"> 
      <Grid Name="ExerciseVis" Background="{StaticResource DarkNeutralBrush}"> 
       <Viewbox Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"> 
        <Image Name="Exerc" CommandManager.Executed="Change_Position" Margin="5 5 5 5" /> 
       </Viewbox> 
       <TextBlock x:Name="txtBox1" VerticalAlignment="Top" HorizontalAlignment="Center" FontSize="30" FontWeight="DemiBold" Text="{Binding TextBox1Text, ElementName=root}" TextAlignment="Center" Margin="36,105,36,0" Height="45" Width="328" /> 
      </Grid> 
     </Grid> 
    </StackPanel> 

"Change_Position"는 파라미터에 도달 할 때 (특히 최대 카운터 값) 이미지를 변경 이벤트가되고 그것은 KinectWindow에 정의 된

private void Change_Position(object sender, EventArgs e)

하고는

DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(Change_Position); dispatcherTimer.Interval = new TimeSpan(0, 0, 0); dispatcherTimer.Start();

012,351에 DispatcherTimer마다 0초 의해 트리거됨에 .xaml.cs

내가 설명한 코드는 제대로 작동하지만 내 질문은 매우 간단합니다 ...이 이벤트를 지속적으로 (타이머가 아닌) 트리거하는 좀 더 "우아한"방법이 있습니까? 내 문제를 해결하기 위해 나와 공유 할 수있는 일부 코드가 있습니까? 미리 감사드립니다.

답변

0

WPF에서 장면을 렌더링 할 때마다 발생하는 CompositionTarget.Rendering 이벤트를 사용할 수 있습니다. 오히려 비싸기 때문에 이벤트 핸들러가 필요하지 않을 때 이벤트 핸들러를 언 Hook하는 것을 잊지 마십시오.

+0

답변 해 주셔서 감사합니다. 그것은 완벽하게 작동합니다! :) – user3506770

관련 문제