UWP操纵三角洲

问题描述 投票:0回答:1

是否有办法使用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;
    }

触摸/捏住画布上的任何位置时,文本框将移动/调整大小。我希望它只有当用户直接触摸文本框的边界时才会发生这种情况。有什么建议?

谢谢!

c# canvas textbox windows-10-universal image-manipulation
1个回答
0
投票

触摸/捏住画布上的任何位置时,文本框将移动/调整大小。

如果您没有指定使用UIElmentproperty和ManipulationMode方法设置哪个AddHandler,它们将对当前整页生效。

如果你只想让它们对TextBox产生影响,你应该按如下方式指定它们:

MyTextBox.ManipulationMode = ManipulationModes.All;    
MyTextBox.AddHandler(ManipulationDeltaEvent, new ManipulationDeltaEventHandler(TextBox_ManipulationDelta), true);

注意ManipulationMode也应该被指定,否则ManipulationTextBox将无效。

© www.soinside.com 2019 - 2024. All rights reserved.