开发者

Can I add an adorner to a DataTemplate item, outside the data template?

Basically, I have a DataTemplate that defines the items in an ItemsControl and 开发者_如何转开发I want to pop a speech bubble above the item when it's clicked. So far, my attempts lead to my adorner showing up inside the DataTemplate and being clipped by the bounds of that DataTemplate instead of being above it. I've been using a nifty adorner control that can be found here: http://www.codeproject.com/KB/WPF/adornedcontrol.aspx.

My XAML looks like this:

    <DataTemplate x:Key="TrackActivityDetailTemplate">
        <ac:AdornedControl HorizontalAlignment="Center" VerticalAlignment="Center" VerticalAdornerPlacement="Outside" >
            <ac:AdornedControl.AdornerContent>
                <TextBlock Foreground="Red" Text="HEY!!!!" />
            </ac:AdornedControl.AdornerContent>
            <Rectangle Name="btn" Height="35" Width="2" Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseLeftButtonDown">
                    <cmd:EventToCommand Command="{Binding Path=SelectActivityCommand}" PassEventArgsToCommand="True"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Rectangle>
        </ac:AdornedControl>
    </DataTemplate>

Any thoughts? Is what I'm attempting to do even possible with adorners?


Yes it is possible. The first thing I would try is setting ClipToBounds=false on the element that is causing the clipping.

That won't always work however, in these cases you can wrap it in a canvas and "float" the canvas. This trick is described here: http://drwpf.com/blog/2007/12/28/cliptoboundsmaybe/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜