置顶:
private
void BringToFront(List<UIElement> CurrentSelection ,UIElementCollection childrens)
{
List<UIElement> selectionSorted = (from item
in CurrentSelection
orderby Canvas.GetZIndex(item
as UIElement) ascending
select item
as UIElement).ToList();
List<UIElement> childrenSorted = (from UIElement item
in childrens
orderby Canvas.GetZIndex(item
as UIElement) ascending
select item
as UIElement).ToList();
int
i = 0; int
j = 0; foreach
(UIElement item in
childrenSorted) {
if
(selectionSorted.Contains(item)) {
int
idx = Canvas.GetZIndex(item); Canvas.SetZIndex(item, childrenSorted.Count - selectionSorted.Count + j++);
}
else {
Canvas.SetZIndex(item, i++);
}
}
} |
置底:
private
void SendToBack(List<UIElement> CurrentSelection ,UIElementCollection childrens)<BR> {
List<UIElement> selectionSorted = (from item
in CurrentSelection
orderby Canvas.GetZIndex(item
as UIElement) ascending
select item
as UIElement).ToList();
List<UIElement> childrenSorted = (from UIElement item
in childrens<BR>
orderby Canvas.GetZIndex(item
as UIElement) ascending
select item
as UIElement).ToList();
int
i = 0; int
j = 0; foreach
(UIElement item in
childrenSorted) {
if
(selectionSorted.Contains(item)) {
int
idx = Canvas.GetZIndex(item); Canvas.SetZIndex(item, j++);
}
else {
Canvas.SetZIndex(item, selectionSorted.Count + i++);
}
}
} |
置下一层:
private
void SendBackward(List<UIElement> CurrentSelection ,UIElementCollection childrens) |
<SPAN class =Apple-style-span> {
List<UIElement> ordered = (from item
in CurrentSelection
orderby Canvas.GetZIndex(item
as UIElement) ascending
select item
as UIElement).ToList();
int
count = </SPAN>childrens.Count;<BR><SPAN class =Apple-style-span>
for
( int
i = 0; i < ordered.Count; i++) {
int
currentIndex = Canvas.GetZIndex(ordered[i]); int
newIndex = Math.Max(i, currentIndex - 1); if
(currentIndex != newIndex) {
Canvas.SetZIndex(ordered[i], newIndex);
IEnumerable<UIElement> it =</SPAN>childrens.OfType<UIElement>().Where(item => Canvas.GetZIndex(item) == newIndex);<BR><SPAN
class =Apple-style-span>
foreach
(UIElement elm in
it) {
if
(elm != ordered[i]) {
Canvas.SetZIndex(elm, currentIndex);
break ;
}
}
}
}
}
</SPAN> |
置上一层:
private
void BringForward(List<UIElement> CurrentSelection ,UIElementCollection childrens) |
<SPAN class =Apple-style-span> {
List<UIElement> ordered = (from item
in CurrentSelection
orderby Canvas.GetZIndex(item
as UIElement) descending
select item
as UIElement).ToList();
int
count = </SPAN>childrens.Count;<BR><SPAN class =Apple-style-span>
for
( int
i = 0; i < ordered.Count; i++) {
int
currentIndex = Canvas.GetZIndex(ordered[i]); int
newIndex = Math.Min(count - 1 - i, currentIndex + 1);
if
(currentIndex != newIndex) {
Canvas.SetZIndex(ordered[i], newIndex);
IEnumerable<UIElement> it =
this .Children.OfType<UIElement>().Where(item => Canvas.GetZIndex(item) == newIndex);
foreach
(UIElement elm in
it) {
if
(elm != ordered[i]) {
Canvas.SetZIndex(elm, currentIndex);
break ;
}
}
}
}
}
</SPAN> |