하나의 아이디어는 Thumb
을 사용자 컨트롤에 추가하고 이에 따라 RotateTransform
을 수정하는 것입니다. Thumb에는 회전 각도를 가져 오는 데 사용할 수있는 DragStarted, DragDelta 및 DragCompleted 이벤트가 포함되어 있습니다.
TextBox
자체를 Thumb의 템플릿의 일부로 만드는 것이 이상적입니다. 즉, 회전 변환을 Thumb.RenderTransform
에 직접 적용하면 TextBox가 Thumb 자체와 함께 회전합니다.
편집 여기에 급한 자갈로 묶은 예가 나와 있습니다.
UserControl을 XAML :
<UserControl x:Class="Test.RotatableUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Thumb DragDelta="OnDragDelta" DragCompleted="OnDragCompleted" DragStarted="OnDragStarted">
<Thumb.Template>
<ControlTemplate TargetType="Thumb">
<Border Padding="5" Background="DarkGray" Cursor="ScrollAll">
<TextBox Text="hello" />
</Border>
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Grid>
</UserControl>
코드 숨김 : 나는 완전한 응답 시간을 가지고 있지만, [RotateTransform (HTTP를 살펴하지 않는
public partial class RotatableUserControl : UserControl
{
private Point _center;
public RotatableUserControl()
{
InitializeComponent();
}
public void OnDragStarted(object sender, DragStartedEventArgs e)
{
var thumb = (Thumb)sender;
_center = new Point(thumb.ActualWidth/2, thumb.ActualHeight/2);
thumb.RenderTransform = (thumb.RenderTransform as RotateTransform) ?? new RotateTransform(0, _center.X, _center.Y);
}
public void OnDragDelta(object sender, DragDeltaEventArgs e)
{
var thumb = (Thumb)sender;
var pos = Mouse.GetPosition(thumb);
var rotate = (RotateTransform)thumb.RenderTransform;
double angle = Math.Atan((pos.X-_center.X)/(pos.Y-_center.Y));
rotate.Angle += angle;
}
public void OnDragCompleted(object sender, DragCompletedEventArgs e)
{
var thumb = (Thumb)sender;
}
}
: // (영문) –