2014-04-10 7 views
1

사용자 테스트 중에 모든 마우스 클릭을 기록 할 수 있도록 터치 스크린 인터페이스를 프로토 타입하고 싶습니다. 스토리 보드 제작에 성공했지만 마우스 클릭 기록에 실패했습니다.Visual Studio 용 Blend에서 마우스 클릭 좌표를 저장하려면 어떻게해야합니까?

나는 고개를 다른 질문 - How do I get the current mouse screen coordinates in WPF?, How do I get the current mouse screen coordinates in WPF? - 하지만 .xaml하거나 그 코드를 적용하는 방법을 이해할 수 없었다 코드 숨김 파일을 내가 원하는 경우

(I 오류 메시지가 모든 시험을 얻었다.) 테스터가 캔버스를 클릭하는 위치를 기록하려면 어떻게 좌표를 추적하고 로그를 다른 파일 형식으로 내보낼 수 있습니까?

답변

0

정말 간단한 예를 들어,

이 모든 사용자가 클릭 한 위치와 때 기록합니다 : 뒤에

enter image description here

<Window x:Class="WpfApplication6.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" 
     Width="525" 
     Height="350" 
     MouseDown="MainWindow_OnMouseDown"> 
    <Grid> 
     <Button Width="75" 
       Margin="5" 
       HorizontalAlignment="Left" 
       VerticalAlignment="Top" 
       Click="Button_Click" 
       Content="_Show log" /> 

    </Grid> 
</Window> 

코드 :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Windows; 
using System.Windows.Input; 

namespace WpfApplication6 
{ 
    /// <summary> 
    ///  Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     private readonly List<Tuple<DateTime, Point>> _list; 

     public MainWindow() 
     { 
      InitializeComponent(); 
      _list = new List<Tuple<DateTime, Point>>(); 
     } 

     private void Button_Click(object sender, RoutedEventArgs e) 
     { 
      IEnumerable<string> @select = _list.Select(s => string.Format("{0} {1}", s.Item1.TimeOfDay, s.Item2)); 
      string @join = string.Join(Environment.NewLine, @select); 
      MessageBox.Show(join); 
     } 

     private void MainWindow_OnMouseDown(object sender, MouseButtonEventArgs e) 
     { 
      Point position = e.GetPosition((IInputElement) sender); 
      var tuple = new Tuple<DateTime, Point>(DateTime.Now, position); 
      _list.Add(tuple); 
     } 
    } 
}