我可以在数据模板之外向 DataTemplate 项添加装饰器吗?
基本上,我有一个 DataTemplate 来定义 ItemsControl 中的项目,并且我想在单击该项目时在该项目上方弹出一个对话框。到目前为止,我的尝试导致我的装饰器出现在 DataTemplate 内部,并被该 DataTemplate 的边界剪切,而不是位于其上方。我一直在使用一个漂亮的装饰器控件,可以在这里找到:http://www. codeproject.com/KB/WPF/adornedcontrol.aspx。
我的 XAML 看起来像这样:
<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>
有什么想法吗?我尝试用装饰器做的事情是否可行?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可能的。我要尝试的第一件事是在导致剪切的元素上设置 ClipToBounds=false 。
但这并不总是有效,在这些情况下,您可以将其包裹在画布中并“浮动”画布。这个技巧在这里描述: http://drwpf.com/blog/2007/12/ 28/cliptoboundsmaybe/
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/