2013-03-25 32 views
1

想知道如何讓用戶在運行時調整TextBox控件的大小,方法是在Windows應用商店中拖動角落。不太重要的是,用於調整所有控件大小的技術是相同的嗎?在Windows商店應用中調整控件大小

感謝和問候!

+0

我可以推薦這個解決方案? http://stackoverflow.com/a/32785999/265706 祝您好運! – 2015-09-25 15:51:00

回答

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; 
} 
+0

非常感謝:D。 – oMETROo 2013-04-08 09:58:05

+0

不客氣,如果您將其標記爲答案,我會很高興。 – Xyroid 2013-04-08 10:02:39

相關問題