手势的操纵事件

时间:2014-04-08 07:49:06

标签: c# wpf xaml

早上好! 我是法国学生,所以如果我的英语不好,我会道歉。 我正在开发一个WPF应用程序的问题:我必须创建一个图像库,可以刷卡,捏缩放,拖入和拖出,就像应用程序Microsoft Surface一样。 (见这里=> http://img.clubic.com/02110128-photo-microsoft-surface-collage.jpg) 我正在使用C#/ XAML中的Visual Studio Express 2013在Windows8上进行开发。 我搜索一些代码或主题可以帮助我做到这一点。我看到我可以使用GestureRecognizer或Triggers,但ManipulationEvent似乎是我需要的。我可以看到,用ManipulationDelta检测滑动事件很容易。但是,我不能使用它,显然缺少一个程序集...也许我很愚蠢,但我找不到哪一个,我搜索几个小时,也许我不能在Windos8上使用它,我真的不喜欢不知道。 = /有人可以帮帮我吗? 我使用Switchers来处理许多页面。我已经有一个带有ScrollViewer的StackPanel,我可以移动Scroolbar并滚动工作,但无法处理StackPanel上的滑动。 我试着用英语和文档制作我的代码(我和初学者一起工作)所以我可能忘记了一两个错误。 ^^'这是我的代码:

XAML

<Grid x:Name="GalleryLayout" HorizontalAlignment="Center" Background="White" VerticalAlignment="Bottom">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Grid x:Name="GalleryGrid" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <ScrollViewer x:Name="Scroll" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" CanContentScroll="True">
            <StackPanel x:Name="GalleryPanel" Grid.Column="1" VerticalAlignment="Center" Margin="20,0,20,0" CanHorizontallyScroll="True" Orientation="Horizontal"/>
        </ScrollViewer>
    </Grid>

C#

public partial class GalleryPhoto : UserControl, ISwitchable
{
    private String[] list; //Array wich will contain the path to all images in a directory : ex C:\\MyPictures\\rainbowdash.jpg
    string pathString;  //Path to the directory where the image are (ex C:\\MyPictures)

    public GalleryPhoto()
    {
        InitializeComponent();

        //Here the code for the Height and Width of XAML buttons...

        pathString = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\" + "Photo";
        list = Directory.GetFileSystemEntries(pathString, "*.*");

        this.Gallery.Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / 2;

        for (int index = 0; index < list.Length; index++) //Create a button for each image found and paint it with an ImageBrush
        {
            System.Drawing.Image image = System.Drawing.Image.FromFile(list[index]);
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
            BitmapSource bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(),
                                                                                  IntPtr.Zero,
                                                                                  Int32Rect.Empty,
                                                                                  BitmapSizeOptions.FromEmptyOptions()
                  );
            bitmap.Dispose();
            ImageBrush brush = new ImageBrush(bitmapSource);

            Button button = new Button();
            button.Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / 10;
            button.Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / 10;
            button.Background = brush;

            this.Gallery.Children.Add(button);
        }

    }

请温柔,拜托,这是我的第一次......:$

0 个答案:

没有答案