只是想知道如何通过在Windows应用商店应用中拖动角来让用户在运行时调整TextBox控件的大小。不太重要的是,用于调整所有控件大小的技术是一样的吗?
感谢和问候!
答案 0 :(得分: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;
}