oMETROo
oMETROo

Reputation: 13

Resizing a control in Windows store app

Was just wondering how I would go about letting the user resize a TextBox control at runtime by dragging its corners in Windows Store App. Less importantly, is the same technique used for the resizing of all controls?

Thank and regards!

Upvotes: 1

Views: 932

Answers (1)

Farhan Ghumra
Farhan Ghumra

Reputation: 15296

Here I am giving you only for textbox as for others it's same.

XAML Code

<Page>
    <Canvas Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid x:Name="grdTextbox" Canvas.Left="300" Canvas.Top="300" Height="40" Width="200">
            <Thumb x:Name="ThumbBottomRight" Background="White" Height="10" Width="10" HorizontalAlignment="Right" DragDelta="ThumbBottomRight_DragDelta" VerticalAlignment="Bottom"/>
            <Thumb x:Name="ThumbBottomLeft" Background="White" Height="10" Width="10" HorizontalAlignment="Left" DragDelta="ThumbBottomLeft_DragDelta" VerticalAlignment="Bottom"/>
            <Thumb x:Name="ThumbTopRight" Background="White" Height="10" Width="10"  HorizontalAlignment="Right" DragDelta="ThumbTopRight_DragDelta" VerticalAlignment="Top"/>
            <Thumb x:Name="ThumbTopLeft" Background="White" Height="10" Width="10" HorizontalAlignment="Left" DragDelta="ThumbTopLeft_DragDelta"  VerticalAlignment="Top"/>
            <TextBox Margin="5" Text="This is resizable textbox"/>
        </Grid>
    </Canvas>
</Page>

C# Code

private void ThumbTopLeft_DragDelta(object sender, DragDeltaEventArgs e)
{
    grdTextbox.Width -= e.HorizontalChange;
    grdTextbox.Height -= e.VerticalChange;
    Canvas.SetLeft(grdTextbox, Canvas.GetLeft(grdTextbox) + e.HorizontalChange);
    Canvas.SetTop(grdTextbox, Canvas.GetTop(grdTextbox) + e.VerticalChange);
}

private void ThumbTopRight_DragDelta(object sender, DragDeltaEventArgs e)
{
    grdTextbox.Width += e.HorizontalChange;
    grdTextbox.Height -= e.VerticalChange;
    Canvas.SetTop(grdTextbox, Canvas.GetTop(grdTextbox) + e.VerticalChange);
}

private void ThumbBottomLeft_DragDelta(object sender, DragDeltaEventArgs e)
{
    grdTextbox.Width -= e.HorizontalChange;
    grdTextbox.Height += e.VerticalChange;
    Canvas.SetLeft(grdTextbox, Canvas.GetLeft(grdTextbox) + e.HorizontalChange);
}

private void ThumbBottomRight_DragDelta(object sender, DragDeltaEventArgs e)
{
    grdTextbox.Width += e.HorizontalChange;
    grdTextbox.Height += e.VerticalChange;
}

Upvotes: 4

Related Questions