0

I have a canvas with a button that the user can press to add a new textbox to the canvas. How can I make it so the user can resize the text box by clicking and dragging on any of the corners of the textbox. Because the textbox is created in the C# code (not XAML), I would prefer code in C# not XAML.

Thanks

EDIT: My question is different than the one referenced because it is in UWP not WPF. These have very different controls. I would appreciate if you could translate the UWP information into UWP C#

kmash
  • 23
  • 4
  • 2
    Possible duplicate of [Resizing TextBox At Runtime in WPF](https://stackoverflow.com/questions/2834452/resizing-textbox-at-runtime-in-wpf) – Lennart Dec 14 '17 at 08:00

1 Answers1

0

You can use Thumb control instead of a textbox. The thumb control provides the functionality for you to write code to customize the drag and drop behavior. A simple code would be:

    <Canvas x:Name="test">
        <Thumb Width="100" Height="100">
            <Thumb.Template>
                <ControlTemplate>
                    <TextBlock HorizontalAlignment="Center" Text="12345"/>
                </ControlTemplate>
            </Thumb.Template>
        </Thumb>
    </Canvas>

A more complex sample could be found from this SO thread from Jay's answer. But please notice you need to customize the logic yourself in order to make it resize like what you need. The reference is just a direction.

Barry Wang
  • 1,459
  • 1
  • 8
  • 12