나는이 두 가지 자원에서 패널 클래스를 작성하려고 해요 :WPF 드래그 가능한 패널 클래스
- WPF: how to make the (0,0) in center inside a Canvas
- http://www.codeproject.com/KB/WPF/DraggingElementsInCanvas.aspx
패널 클래스는 것 두 개의 연결된 속성 "X"와 "Y"이고 어떤 원소가 x와 y에 0을 준다면 패널의 중앙에 놓일 것입니다. 이 패널을 통해 사용자는 주변을 끌 수 있습니다. 이 수업을 도와주세요. 나는 WPF에 대해 매우 익숙하다.
이것은 내가 얼마나 멀리 왔는지입니다. 이제는 구현하려고 시도했지만 작동하지 않습니다. GetTop, GetLeft, GetBottom, GetRight 함수는 기본적으로 패널 클래스에 정의되어 있지 않으며 필요한 것입니다. 이 4 가지 방법이있는 경우 여기에서 드래그 기능을 구현할 수 있습니다.
using System;
using System.Linq;
using System.Windows;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Media;
namespace SmartERP.Elements
{
public class SmartCanvas : Panel
{
public static readonly DependencyProperty TopProperty;
public static readonly DependencyProperty LeftProperty;
public static readonly DependencyProperty BottomProperty;
public static readonly DependencyProperty RightProperty;
static SmartCanvas()
{
TopProperty = DependencyProperty.Register("Top", typeof(double), typeof(SmartCanvas), new PropertyMetadata(0.0));
LeftProperty = DependencyProperty.Register("Left", typeof(double), typeof(SmartCanvas), new PropertyMetadata(0.0));
BottomProperty = DependencyProperty.Register("Bottom", typeof(double), typeof(SmartCanvas), new PropertyMetadata(0.0));
RightProperty = DependencyProperty.Register("Right", typeof(double), typeof(SmartCanvas), new PropertyMetadata(0.0));
}
public double Top
{
get { return (double)base.GetValue(TopProperty); }
set { base.SetValue(TopProperty, value); }
}
public double Bottom
{
get { return (double)base.GetValue(BottomProperty); }
set { base.SetValue(BottomProperty, value); }
}
public double Left
{
get { return (double)base.GetValue(LeftProperty); }
set { base.SetValue(LeftProperty, value); }
}
public double Right
{
get { return (double)base.GetValue(RightProperty); }
set { base.SetValue(RightProperty, value); }
}
private double GetTop(UIElement element)
{
return (double)this.GetValue(TopProperty);
}
private double GetLeft(UIElement element)
{
return (double)this.GetValue(LeftProperty);
}
private double GetBottom(UIElement element)
{
return (double)this.GetValue(BottomProperty);
}
private double GetRight(UIElement element)
{
return (double)this.GetValue(RightProperty);
}
protected override Size ArrangeOverride(Size arrangeSize)
{
Point middle = new Point(arrangeSize.Width/2, arrangeSize.Height/2);
foreach (UIElement element in base.InternalChildren)
{
if (element == null)
{
continue;
}
double x = 0.0;
double y = 0.0;
double left = GetLeft(element);
if (!double.IsNaN(left))
{
x = left;
}
double top = GetTop(element);
if (!double.IsNaN(top))
{
y = top;
}
element.Arrange(new Rect(new Point(middle.X + x, middle.Y + y), element.DesiredSize));
}
return arrangeSize;
}
}
}
지금까지 무엇을 가지고 계신가요? – Heinzi
어떻게 구현할 수 있습니까? 도와주세요. –
Soham, 당신은 구현하려는 것을 설명하지 않았습니다. 우리는 질문이 무엇인지 모를 때 어떻게 대답 할 수 있습니까? 무엇을 성취하려고합니까? 귀하의 코드는 현재 무엇을하고 있습니까? 기대 한 행동과 어떻게 다른가? 맞춤 패널은 어떻게 사용됩니까 (예제 코드 포함)? 이러한 것들을 설명하면 여기 누군가가 올바른 방향으로 당신을 가리킬 수 있습니다. –