是否有办法使用ManipulationDelta Handler操作的元素只有在用户点击或触摸该特定元素时才会被操作?
到目前为止,我有以下代码:
public void AddTextButton_Click(object sender, RoutedEventArgs e)
{
TextBox MyTextBox = new TextBox();
MyTextBox.Background = new SolidColorBrush(Colors.White);
MyTextBox.PlaceholderText = "Text";
MyTextBox.Width = 250;
MyTextBox.Height = 100;
ManipulationMode = ManipulationModes.All;
MyTextBox.RenderTransform = textBoxTransforms;
AddHandler(ManipulationDeltaEvent, new ManipulationDeltaEventHandler(TextBox_ManipulationDelta), true);
parentCanvas.Children.Add(MyTextBox);
}
void TextBox_ManipulationDelta(object sender,
ManipulationDeltaRoutedEventArgs e)
{
dragTextBox.X += e.Delta.Translation.X;
dragTextBox.Y += e.Delta.Translation.Y;
resizeTextBox.ScaleX *= e.Delta.Scale;
resizeTextBox.ScaleY *= e.Delta.Scale;
}
触摸/捏住画布上的任何位置时,文本框将移动/调整大小。我希望它只有当用户直接触摸文本框的边界时才会发生这种情况。有什么建议?
谢谢!
触摸/捏住画布上的任何位置时,文本框将移动/调整大小。
如果您没有指定使用UIElment
property和ManipulationMode
方法设置哪个AddHandler,它们将对当前整页生效。
如果你只想让它们对TextBox
产生影响,你应该按如下方式指定它们:
MyTextBox.ManipulationMode = ManipulationModes.All;
MyTextBox.AddHandler(ManipulationDeltaEvent, new ManipulationDeltaEventHandler(TextBox_ManipulationDelta), true);
注意ManipulationMode
也应该被指定,否则Manipulation
的TextBox
将无效。