2011-12-07 4 views
2

멀티 터치 응용 프로그램을 개발 중입니다. 핀치 줌을 할 때 이미지를 전체 화면 모드로 여는 한 가지 방법이 있습니까?WPF에서 멀티 터치로 전체 화면 이미지 열기

코드는 이것이다 : 나는 .cs 내가 그 코드를 추가해야

에서이 클래스를 사용하고

<Window x:Class="TouchRect.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:TouchRect" 
    Title="MainWindow" Height="700" Width="1000"> 
<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="189*"/> 
     <RowDefinition Height="472*"/> 
    </Grid.RowDefinitions> 
    <!--<local:RulerCanvas x:Name="canvas" >--> 

     <Image x:Name="image3" Width="74" Height="49" IsManipulationEnabled="True" Source="flower3.jpg" Margin="446,-268,458,408"> 
      <Image.RenderTransform> 
       <MatrixTransform Matrix="2.41806325085411,0,0,2.41806325085411,280.737615796121,292.420001677231" /> 
      </Image.RenderTransform> 
     </Image> 
     <Image x:Name="image2" Width="74" Height="49" IsManipulationEnabled="True" Source="flower2.jpg" Margin="110,-266,794,406" Stretch="Fill" > 
      <Image.RenderTransform> 
       <MatrixTransform Matrix="2.41806325085411,0,0,2.41806325085411,280.737615796121,292.420001677231"/> 
      </Image.RenderTransform> 
     </Image> 
     <Image x:Name="image" Width="74" Height="49" IsManipulationEnabled="True" Source="flower.jpg" Stretch=" fill" Margin="-248,-271,1152,411"> 
      <Image.RenderTransform> 
       <MatrixTransform Matrix="2.41806325085411,0,0,2.41806325085411,280.737615796121,292.420001677231" /> 
      </Image.RenderTransform> 
     </Image> 
    <MediaElement x:Name="media" Source="C:\Users\Public\Videos\Sample Videos\Wildlife.wmv" Canvas.Left="183" Canvas.Top="151" LoadedBehavior="Manual" IsManipulationEnabled="True" Margin="37,18,38,38" Grid.Row="1" /> 
    <DataGrid AutoGenerateColumns="False" Height="0" HorizontalAlignment="Left" Margin="100,86,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="217" /> 
    <!--</local:RulerCanvas>--> 

</Grid> 

?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 
using System.Windows.Media.Animation; 

namespace TouchRect 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 
      media.Volume = 100; 
      media.Play(); 
      this.Loaded += new RoutedEventHandler(MainWindow_Loaded); 

     } 

     void MainWindow_Loaded(object sender, RoutedEventArgs e) 
     { 

      canvas.ManipulationStarting += new EventHandler<ManipulationStartingEventArgs>(image_ManipulationStarting); 
      canvas.ManipulationDelta += new EventHandler<ManipulationDeltaEventArgs>(image_ManipulationDelta); 
      // inertia 
      canvas.ManipulationInertiaStarting += new EventHandler<ManipulationInertiaStartingEventArgs>(canvas_ManipulationInertiaStarting); 


     } 


void canvas_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e) 
{     
     // Decrease the velocity of the Rectangle's movement by 
     // 10 inches per second every second. 
     // (10 inches * 96 DIPS per inch/1000ms^2) 
     e.TranslationBehavior = new InertiaTranslationBehavior() 
     { 
      InitialVelocity = e.InitialVelocities.LinearVelocity, 
      DesiredDeceleration = 10.0 * 96.0/(1000.0 * 1000.0) 
     }; 

     // Decrease the velocity of the Rectangle's resizing by 
     // 0.1 inches per second every second. 
     // (0.1 inches * 96 DIPS per inch/(1000ms^2) 
     e.ExpansionBehavior = new InertiaExpansionBehavior() 
     { 
      InitialVelocity = e.InitialVelocities.ExpansionVelocity, 
      DesiredDeceleration = 0.1 * 96/1000.0 * 1000.0 
     }; 

     // Decrease the velocity of the Rectangle's rotation rate by 
     // 2 rotations per second every second. 
     // (2 * 360 degrees/(1000ms^2) 
     e.RotationBehavior = new InertiaRotationBehavior() 
     { 
      InitialVelocity = e.InitialVelocities.AngularVelocity, 
      DesiredDeceleration = 720/(1000.0 * 1000.0) 
     }; 
     e.Handled = true;     
} 

UIElement last;  


void image_ManipulationStarting(object sender, ManipulationStartingEventArgs e) 
{ 
    // lazy hack not in the blog post.. 
    var uie = e.OriginalSource as UIElement;  
    if (uie != null) 
    { 
     if (last != null) Canvas.SetZIndex(last, 0); 
     Canvas.SetZIndex(uie, 2); 
     last = uie; 
    } 

    //canvas is the parent of the image starting the manipulation; 
    //Container does not have to be parent, but that is the most common scenario 
    e.ManipulationContainer = canvas; 
    e.Handled = true; 
    // you could set the mode here too 
    // e.Mode = ManipulationModes.All;    
} 

void image_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) 
{ 
    //this just gets the source. 
    // I cast it to FE because I wanted to use ActualWidth for Center. You could try RenderSize as alternate 
    var element = e.Source as FrameworkElement; 
    if (element != null) 
    { 
     //e.DeltaManipulation has the changes 
     // Scale is a delta multiplier; 1.0 is last size, (so 1.1 == scale 10%, 0.8 = shrink 20%) 
     // Rotate = Rotation, in degrees 
     // Pan = Translation, == Translate offset, in Device Independent Pixels 

     var deltaManipulation = e.DeltaManipulation; 
     var matrix = ((MatrixTransform)element.RenderTransform).Matrix;    
     // find the old center; arguaby this could be cached 
     Point center = new Point (element.ActualWidth/2, element.ActualHeight/2) ; 
     // transform it to take into account transforms from previous manipulations 
     center = matrix.Transform(center); 
     //this will be a Zoom. 
     matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y); 
     // Rotation 
     matrix.RotateAt(e.DeltaManipulation.Rotation, center.X, center.Y);    
     //Translation (pan) 
     matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); 

     ((MatrixTransform)element.RenderTransform).Matrix = matrix; 

     e.Handled = true; 

     // We are only checking boundaries during inertia 
     // in real world, we would check all the time 
     if (e.IsInertial) 
     { 
      Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize); 

      Rect shapeBounds = element.RenderTransform.TransformBounds(new Rect(element.RenderSize)); 

      // Check if the element is completely in the window. 
      // If it is not and intertia is occuring, stop the manipulation. 
      if (e.IsInertial && !containingRect.Contains(shapeBounds)) 
      { 
       //Report that we have gone over our boundary 
       e.ReportBoundaryFeedback(e.DeltaManipulation); 
       // comment out this line to see the Window 'shake' or 'bounce' 
       // similar to Win32 Windows when they reach a boundary; this comes for free in .NET 4     
       e.Complete(); 
      } 

     }   
    } 
} 


    } 
+0

댓글에 넣기에는 너무 큰 내용을 게시해야하는 경우 질문에 포함해야합니다. –

답변

0

코드가 뒤섞여 있어야합니다. 다음 단계를 수행합니다

this.WindowState = WindowState.Normal; 
this.WindowStyle = WindowStyle.None; 
this.WindowState = WindowState.Maximized; 
this.Topmost = true; 
this.Top = 0; 
this.Left = 0; 

겉보기 쓸모 첫 번째 줄은 실제로 (윈도우가 이미 최대화되어있는 경우 작업 표시 줄에는 적용되지 않습니다 최대화의) WPF 윈도우의 이상한 행동에 해결된다.

멀티 터치는 here입니다.

+0

감사합니다. 나는 위에 답했다. –