为什么AdornerLayers总是最顶层?有办法改变吗? [英] Why AdornerLayers are always the top most layers? Is there a way to change it?

查看:124
本文介绍了为什么AdornerLayers总是最顶层?有办法改变吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 为什么装饰图层总是呈现为应用程序中的最顶层(在AdornerDecorator下-参见屏幕截图)?

  2. 是否可以更改装饰者可以绘制到的图层/级别?

在以下屏幕截图中,将AdornerLayer添加到AdornerDecorator,并将Adorners(MyAdorners)添加到此AdornerLayer。但是,AdornerLayer的检索方式如下:

In the following screenshot, AdornerLayer is added to AdornerDecorator and the Adorners (MyAdorners) are added to this AdornerLayer. But the AdornerLayer is retrieved like this,

        AdornerLayer layer1 = AdornerLayer.GetAdornerLayer(button1);
        layer1.Add(new MyAdorner(button1));

推荐答案

要回答我的第二个问题,

To answer my second question,


有没有办法改变装饰物可以绘制到的层/级别?

Is there a way to change the layer/level on to which the adorners can be drawn?

我想我已经找到了解决方案。只需将AdornerDecorator元素放在需要渲染装饰物的层上即可。任何需要装饰层的控件都将使用此AdornerDecorator元素放置其装饰器。

I guess I have found a solution. Just place an AdornerDecorator element around the level on to which the adorners needs to be rendered. Any control requiring an adorner layer would use this AdornerDecorator element to place its decorators.

在这里,我使用以下代码片段将装饰器移到了另一个级别。

Here I have moved the adorners to a different level using the following code snippet.

<Window x:Class="CustomAdornerLayer.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
    <StackPanel Background="Yellow" Width="Auto">
        <Button>Button3</Button>
    </StackPanel>
    <AdornerDecorator>
        <Grid>
            <AdornerDecorator>
                <Button x:Name="button1" Margin="70,73,265,158">Button1</Button>
            </AdornerDecorator>
            <AdornerDecorator>
                <Button x:Name="button2" Margin="87,51,248,180">Button2</Button>
            </AdornerDecorator>
        </Grid>
    </AdornerDecorator>
</Grid>

虽然仍在查询AdornerLayer

While the AdornerLayer is still queried in the same way,

        AdornerLayer layer1 = AdornerLayer.GetAdornerLayer(button1);
        layer1.Add(new MyAdorner(button1));
        AdornerLayer layer2 = AdornerLayer.GetAdornerLayer(button2);
        layer2.Add(new MyAdorner(button2));

如果我错了,请纠正我。

Kindly correct me if I am wrong.

这篇关于为什么AdornerLayers总是最顶层?有办法改变吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆