Beispiel #1
0
        void Page_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if(_dragged != null)
            {
                //Set correct Z-index
                Rect r = new Rect(Canvas.GetLeft(_dragged), Canvas.GetTop(_dragged), _dragged.Width, _dragged.Height);
                var t = from uc in _objects
                        where uc != _dragged && (
                                                    uc.ContainsPoint(r.TopLeft()) || uc.ContainsPoint(r.TopRight()) ||
                                                    uc.ContainsPoint(r.BottomLeft()) || uc.ContainsPoint(r.BottomRight()))
                        orderby Canvas.GetZIndex(uc) descending
                        select uc;

                int z;
                if(t.Count() > 0)
                    z = Canvas.GetZIndex(t.FirstOrDefault()) + 1;
                else
                    z = 0;

                Canvas.SetZIndex(_dragged, z);

            }
            _dragged = null;
        }