在 Windows 应用商店应用中调整控件的大小 [英] Resizing a control in Windows store app
本文介绍了在 Windows 应用商店应用中调整控件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是想知道如何让用户在运行时通过拖动 Windows 应用商店应用程序中的角来调整 TextBox 控件的大小.不太重要的是,是否使用相同的技术来调整所有控件的大小?
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?
谢谢和问候!
推荐答案
这里我只给你文本框,其他都是一样的.
Here I am giving you only for textbox as for others it's same.
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;
}
这篇关于在 Windows 应用商店应用中调整控件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文