我有一个包含 4 个 UIElement 的网格。我已经订阅了所有元素上的事件 ManipulationStarted 和 ManipulationCompleted。
在 ManipulationStarted 时,我更改了元素的颜色,在 ManipulationCompleted 时,我将其设置回原来的颜色。
这有效,但仅适用于一个项目,如果我点击一个项目然后在不离开手指的情况下移动到另一个项目,它不会改变颜色。
为了更清楚:
这是我打开应用程序时看到的内容。网格中的 4 个 UIElement(矩形)。
这是我将手指放在矩形上时看到的。
当我将手指放在一个矩形上,然后在不抬起手指的情况下将手指移到另一个矩形上时,这就是我想要发生的情况,但它并没有发生。它只适用于一个矩形。
这是每个矩形上的事件代码:
private void Rectangle_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
e.Handled = true;
if(sender is Rectangle)
((Rectangle)sender).Fill = new SolidColorBrush(Colors.Purple);
}
private void Rectangle_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
e.Handled = true;
if (sender is Rectangle)
((Rectangle)sender).Fill = originalColor;
}
最佳答案
解决了! :D
我在矩形上使用 MouseEnter 事件来更改颜色,在包含它们的 Grid 上使用 MouseLeave 事件将其设置回原来的颜色!它完美无缺! :D
关于c# - 如何使用相同的触摸在多个 UIElement 上触发 ManipulationStarted?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36794917/