キャンバスをスクロールバーに入れて、ズームとパンができるようにしました。しかし、私はまた、ユーザーの入力要素(テキストボックス、画像など)をピンチ機能でリサイズできるようにしようとしています。ここではインタフェースの基礎のための私のXAMLコードは次のとおりです。UWPキャンバスのUI要素をScrollViewerでサイズ変更
<Grid>
<RelativePanel>
<Button ... />
<Button ... />
<Button />
<ScrollViewer
VerticalScrollMode="Auto"
HorizontalScrollMode="Auto"
HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Visible"
ZoomMode="Enabled"
MinZoomFactor="1"
MaxZoomFactor="5"
HorizontalAlignment="Left"
VerticalAlignment="Top"
RelativePanel.Below="AddTextButton">
<Canvas Name="parentCanvas" Height="10000" Width="10000" >
<InkCanvas Name="inkCanvas" Height="10000" Width="10000"
Visibility="Visible" />
</Canvas>
</ScrollViewer>
</RelativePanel>
</Grid>
私も(ドラッグ/サイズを変更)テキストボックスを追加し、操作イベントを処理するために、このC#のコードを持っている:
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)
{
// Move the TextBox.
dragTextBox.X += e.Delta.Translation.X;
dragTextBox.Y += e.Delta.Translation.Y;
resizeTextBox.ScaleX *= e.Delta.Scale;
resizeTextBox.ScaleY *= e.Delta.Scale;
}
このC#のコードをキャンバスがスクロールビューアに含まれていない場合に機能します。スクロールビューアでサイズ変更(タッチ/ピンチ機能付き)を行う方法に関する提案はありますか?
ありがとうございます!