c# - 如何使用相同的触摸在多个 UIElement 上触发 ManipulationStarted?

标签 c# xaml silverlight windows-phone-8.1 windows-phone

我有一个包含 4 个 UIElement 的网格。我已经订阅了所有元素上的事件 ManipulationStarted 和 ManipulationCompleted。

在 ManipulationStarted 时,我更改了元素的颜色,在 ManipulationCompleted 时,我将其设置回原来的颜色。

这有效,但仅适用于一个项目,如果我点击一个项目然后在不离开手指的情况下移动到另一个项目,它不会改变颜色。

为了更清楚:

This is the normal situation

这是我打开应用程序时看到的内容。网格中的 4 个 UIElement(矩形)。

This is what happens when I press on an element

这是我将手指放在矩形上时看到的。

This is what I want to happen

当我将手指放在一个矩形上,然后在不抬起手指的情况下将手指移到另一个矩形上时,这就是我想要发生的情况,但它并没有发生。它只适用于一个矩形。

这是每个矩形上的事件代码:

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/

相关文章:

silverlight - 您如何调试 Share Picker 扩展?

silverlight - Silverlight 和 WCF 服务的通信异常

c# - 如何使用打开文件对话框选择文件夹

c# - 获取派生类型类

c# - 对可能包含斜杠的字符串进行编码和解码

c# - 在 WinRT XAML/C# 中使用 Adorner、AdorrnerLayer、AdornerDecorator、Thumb 移动和调整组件大小

c# - 在 Entity Framework 5 中重新创建和处理 dbcontext

xaml - 如何将 Observable Collection 的整个元素绑定(bind)到 Xamarin Forms 中的 ContentView

xaml - 在水平堆栈面板或包装面板中很好地包装文本?

c# - Silverlight 工具包 TreeView 控件和可扩展性