1

只是想知道如何让用户在运行时通过在 Windows Store App 中拖动它的角来调整 TextBox 控件的大小。不太重要的是,是否使用相同的技术来调整所有控件的大小?

感谢和问候!

4

1 回答 1

4

在这里,我只为您提供文本框,其他人也一样。

XAML 代码

<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# 代码

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;
}
于 2013-03-26T10:49:27.533 回答