通过出血的adorners

时间:2010-08-09 22:51:37

标签: .net wpf

我有一个这样定义的扩展器;

<Canvas Panel.ZIndex="99">
 <Expander HorizontalAlignment="Left" VerticalAlignment="Top">
  <StackPanel Background="White">
    <TextBlock>Some Stuff in the Expander</TextBlock>
   </StackPanel>
 </Expander>
</Canvas>

这允许扩展器绘制其他内容。我遇到的问题是当扩展器下的内容被装饰时(在我的情况下带有指示用户输入错误的红色边框),装饰器总是通过扩展器渗出。

1 个答案:

答案 0 :(得分:2)

通过执行以下操作将AdornerDecorator中的其他控件包裹起来:

<Grid>
    <Canvas Panel.ZIndex="99">
        <Expander HorizontalAlignment="Left" VerticalAlignment="Top">
            <StackPanel Background="White">
                <TextBlock>Some Stuff in the Expander</TextBlock>
            </StackPanel>
        </Expander>
    </Canvas>
    <AdornerDecorator>
        <!-- Other content here -->
        <StackPanel>
            <TextBox Text="{Binding Foo, ValidatesOnDataErrors=True}"/>
        </StackPanel>
    </AdornerDecorator>
</Grid>

默认情况下,唯一的AdornerDecorator是Window创建的。装饰者将在该层中渲染,该层位于所有Window的内容之前。如果将其他元素包装在AdornerDecorator中,它将为它们创建一个新的AdornerLayer。将Canvas放置在比AdornerDecorator更高的ZIndex上将导致Canvas在AdornerLayer前面呈现。