Silverlight 动态仪表板界面

Silverlight 动态仪表板界面,silverlight,dynamic,dashboard,Silverlight,Dynamic,Dashboard,我想在Silverlight中创建一个类似于以下内容的界面。 我需要创建一个仪表板,其中可以使用Silverlight重新安排不同的元素。仪表板元素可以是不同的用户控件,这些控件可能依次包含图表、量规、网格。。。。。。用户应该能够动态添加和删除仪表板元素。用户还应该能够使用拖放来重新定位仪表板元素 如果有一些代码示例可以让我开始,那将非常好,因为我们刚刚开始一些Silverlight开发 谢谢, Pratik请查看中的。它非常适合构建仪表板。甚至还有一个关于如何在……上使用它的教程,你也可以试

我想在Silverlight中创建一个类似于以下内容的界面。

我需要创建一个仪表板,其中可以使用Silverlight重新安排不同的元素。仪表板元素可以是不同的用户控件,这些控件可能依次包含图表、量规、网格。。。。。。用户应该能够动态添加和删除仪表板元素。用户还应该能够使用拖放来重新定位仪表板元素

如果有一些代码示例可以让我开始,那将非常好,因为我们刚刚开始一些Silverlight开发

谢谢, Pratik

请查看中的。它非常适合构建仪表板。甚至还有一个关于如何在……上使用它的教程,你也可以试试。您可以使用Visifire中的图表和仪表,并实现拖放行为。下面的代码将帮助您在应用程序中构建拖放行为。您可以将此行为附加到Silverlight或WPF应用程序中的图表或仪表

您可以从下面的my SkyDrive下载源代码(DragelementsinCanvasBehavior.zip

[“Hello world”拖放行为类。]

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;

namespace DragInCanvasBehaviour
{
    public class DragInCanvasBehaviour : Behavior<UIElement>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            this.AssociatedObject.MouseLeftButtonDown += AssociatedObject_MouseLeftButtonDown;
            this.AssociatedObject.MouseMove += AssociatedObject_MouseMove;
            this.AssociatedObject.MouseLeftButtonUp += AssociatedObject_MouseLeftButtonUp;
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            this.AssociatedObject.MouseLeftButtonDown -= AssociatedObject_MouseLeftButtonDown;
            this.AssociatedObject.MouseMove -= AssociatedObject_MouseMove;
            this.AssociatedObject.MouseLeftButtonUp -= AssociatedObject_MouseLeftButtonUp;
        }

        private Canvas canvas;
        private bool IsDragging = false;
        private Point mouseOffset;

        private void AssociatedObject_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (canvas == null)
                canvas = (Canvas)VisualTreeHelper.GetParent(this.AssociatedObject);
            IsDragging = true;
            mouseOffset = e.GetPosition(AssociatedObject);
            AssociatedObject.CaptureMouse();
        }

        private void AssociatedObject_MouseMove(object sender, MouseEventArgs e)
        {

            if (IsDragging)
            {
                FrameworkElement element = AssociatedObject as FrameworkElement;
                FrameworkElement parent = element.Parent as FrameworkElement;

                Point point = e.GetPosition(parent);
                AssociatedObject.SetValue(Canvas.TopProperty, point.Y - element.Height /2);
                AssociatedObject.SetValue(Canvas.LeftProperty, point.X - element.Width / 2);
            }
        }

        private void AssociatedObject_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (IsDragging)
            {
                AssociatedObject.ReleaseMouseCapture();
                IsDragging = false;
            }
        }

    }
}
使用系统;
Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Documents;
使用System.Windows.Ink;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Animation;
使用System.Windows.Shapes;
使用System.Windows.Interactive;
命名空间DraginavasBehavior
{
公共类绘图行为:行为
{
受保护的覆盖无效附加()
{
base.onatached();
this.AssociatedObject.MouseLeftButtonDown+=AssociatedObject\u MouseLeftButtonDown;
this.AssociatedObject.MouseMove+=AssociatedObject\u MouseMove;
this.AssociatedObject.MouseLeftButtonUp+=AssociatedObject\u MouseLeftButtonUp;
}
附加时受保护的覆盖无效()
{
base.OnDetaching();
this.AssociatedObject.MouseLeftButtonDown-=AssociatedObject\u MouseLeftButtonDown;
this.AssociatedObject.MouseMove-=AssociatedObject\u MouseMove;
this.AssociatedObject.MouseLeftButtonUp-=AssociatedObject\u MouseLeftButtonUp;
}
私人帆布;
私有布尔ISDRAGING=假;
私人点鼠标偏移;
private void Associated object_MouseLeftButtonDown(对象发送方,MouseButtonEventArgs e)
{
if(canvas==null)
canvas=(canvas)VisualTreeHelper.GetParent(this.AssociatedObject);
IsDraging=true;
mouseOffset=e.GetPosition(关联对象);
AssociatedObject.CaptureMouse();
}
私有无效关联对象\u MouseMove(对象发送方,MouseEventArgs e)
{
if(ISDRAGING)
{
FrameworkElement=关联对象作为FrameworkElement;
FrameworkElement父元素=元素。父元素作为FrameworkElement;
点=e.GetPosition(父项);
AssociatedObject.SetValue(Canvas.TopProperty,point.Y-element.Height/2);
AssociatedObject.SetValue(Canvas.LeftProperty,point.X-element.Width/2);
}
}
private void Associated object_MouseLeftButtonUp(对象发送方,MouseButtonEventArgs e)
{
if(ISDRAGING)
{
AssociatedObject.ReleaseMouseCapture();
IsDraging=错误;
}
}
}
}
希望这有帮助