2017-12-29 50 views
0

ManipulationDeltaHandlerで操作される要素は、ユーザーがその特定の要素をクリックまたはタッチしたときにのみ操作できるようにする方法はありますか?UWP操作Delta

私がこれまでに次のコードを持っている:キャンバス上の任意の場所ピンチ/タッチすると

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; 
    } 

、テキストボックスには、サイズ変更/移動します。これは、ユーザーがテキストボックスの境界内で直接触れる場合にのみ発生します。助言がありますか?

ありがとうございます!

+0

私は覚えていませんが、MyTextBoxでAddHandlerを呼び出すことはできませんか?ように:MyTextBox.AddHandler(..); – rokkerboci

+0

私はこれを試しましたが、何らかの理由でこれがテキストボックスのすべてのドラッグ/リサイズ機能を失います... – kmash

答えて

0

キャンバス上の任意の場所をタッチ/ピンチすると、テキストボックスが移動/サイズ変更されます。

あなたはManipulationMode財産とAddHandler方法で設定するためにどのUIElment指定しなかった場合は、現在のページ全体のために効果がかかります。あなたが唯一の彼らはTextBoxに影響を取るしたい場合は、次のよう

、あなたはそれらを指定する必要があります:ManipulationModeも指定されるべきであることを

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

ご注意を、そうでない場合はTextBoxためManipulationが動作しません。