【发布时间】:2017-06-02 15:20:24
【问题描述】:
我确定这是一个超级简单的,但我正在开发一个 C# UWP 应用程序并试图制作一个可拖动的用户控件,但在我的鼠标事件中我收到以下错误:
CS1061“MouseEventArgs”不包含“GetPosition”的定义,并且找不到接受“MouseEventArgs”类型的第一个参数的扩展方法“GetPosition”(您是否缺少 using 指令或程序集引用?)
我发现我在堆栈上使用的这个示例 (Dragging a WPF user control) 并且之前使用鼠标按下事件在 winforms 的列表框之间拖动项目,但没有这个问题。
这是我的代码:
<UserControl
x:Class="HopHaus.TimerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HopHaus"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400" Width="120" Height="60">
<Grid Margin="0,0,0,167" Width="120">
<Rectangle Fill="#FF404040" HorizontalAlignment="Left" Height="60" Margin="1,0,-1,-133" Stroke="Black" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="timersetBox" Margin="-1,-2,1,-59" TextWrapping="Wrap" Text="00" VerticalAlignment="Top" Height="60" BorderBrush="Transparent" FontFamily="Fonts/DIGITAL.TTF#Digital" Foreground="#FF72FB00" FontSize="50" Background="Transparent" TextAlignment="Right" AcceptsReturn="True" SelectionHighlightColor="#000078D7" Width="120"/>
<Border x:Name="dragBrdr" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="59" Margin="2,0,0,-59" VerticalAlignment="Top" Width="118"/>
</Grid>
</UserControl>
还有:
public sealed partial class TimerControl : UserControl
{
Point currentPoint;
Point anchorPoint;
bool isInDrag;
public TimerControl()
{
this.InitializeComponent();
}
private TranslateTransform transform = new TranslateTransform();
private void root_MouseMove(object sender, MouseEventArgs e)
{
if (isInDrag)
{
var element = sender as FrameworkElement;
currentPoint = e.GetPosition(null);
transform.X += currentPoint.X - anchorPoint.X;
transform.Y += (currentPoint.Y - anchorPoint.Y);
this.RenderTransform = transform;
anchorPoint = currentPoint;
}
}
}
我同时使用System.Windows.Input & using Windows.Devices.Input
非常感谢您提供的任何帮助。
【问题讨论】:
标签: c# wpf visual-studio xaml uwp