【发布时间】:2011-09-13 19:30:11
【问题描述】:
我有以下代码来处理拇指控件抛出的鼠标拖动事件。它适用于标准代码,例如 SettingView.xaml 和 SettingView.xaml.cs
但是我如何在我的 SettingViewModel.cs 文件中处理这个问题。
到目前为止,我能够使用带有参数的 DelegateCommand(或 RelayCommand)来连接点击,但是我如何从事件发送的参数中获取输入?例如拖动事件提供事件参数 e.HorizontalChange 和 e.VerticalChange。请看下面我的代码原型。
非常感谢任何优雅的解决方案。
提前致谢。
================================================ ==================================== SettingView.xaml
Thumb Name="thumbWest" DragDelta="thumbWest_DragDelta
SettingView.xaml.cs
private void thumbWest_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
_captureMargin.Left = _captureMargin.Left + e.HorizontalChange;
if (e.HorizontalChange < 0)
{
// Drag towards West
_widthRect = _widthRect + Math.Abs(e.HorizontalChange);
}
if (e.HorizontalChange > 0)
{
// Drag towards East
_widthRect = _widthRect - e.HorizontalChange;
}
}
【问题讨论】:
标签: wpf mvvm event-handling command