【发布时间】:2015-01-08 01:26:13
【问题描述】:
我是 C# 新手,我正在尝试学习 Windows Phone 开发。我想要做的只是能够用你的手指移动一个矩形,但我得到了这个错误:
Error 1 No overload for 'Drag_ManipulationDelta' matches delegate 'System.EventHandler<Windows.UI.Xaml.Input.ManipulationDeltaEventHandler>' C:\Users\Zach\documents\visual studio 2013\Projects\App2\App2\MainPage.xaml.cs 35 46 App2
我之前看过这个“方法匹配委托没有重载”的问题,但由于我是新手,所以我对发生的事情有点困惑。
这里是完整的代码:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Windows;
using System.Windows.Input;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Shapes;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
namespace App2
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private int buttonCount = 0;
private TranslateTransform dragTranslation; // For changing position of myRectangle
private SolidColorBrush redRect = new SolidColorBrush(Windows.UI.Colors.Red);
public MainPage()
{
this.InitializeComponent();
myRectangle.ManipulationDelta += new EventHandler<ManipulationStartedEventHandler>(Drag_ManipulationDelta);
//myRectangle.ManipulationDelta += new System.EventHandler<ManipulationDeltaEventArgs>(Drag_ManipulationDelta);
dragTranslation = new TranslateTransform();
myRectangle.RenderTransform = this.dragTranslation;
this.NavigationCacheMode = NavigationCacheMode.Required;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// this event is handled for you.
}
// < Called when myButton is pressed >
private void myButton_Click(object sender, RoutedEventArgs e)
{
buttonCount += 1;
myRectangle.Fill = redRect;
resultText.Text = "";
// Determines visibility of myRectangle
if(buttonCount % 2 != 0)
{
myRectangle.Visibility = Visibility.Visible;
}
else
{
myRectangle.Visibility = Visibility.Collapsed;
}
}
// < Called when myRectangle is pressed >
private void myRectangle_PointerPressed(object sender, PointerRoutedEventArgs e)
{
resultText.Text = "You touched the rectangle.";
}
void Drag_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
// Move the rectangle.
dragTranslation.X += e.Delta.Translation.X;
dragTranslation.Y += e.Delta.Translation.Y;
//dragTranslation.Y += e.DeltaManipulation.Translation.Y;
}
}
}
谢谢
【问题讨论】:
标签: c# visual-studio windows-phone