如何使 WPF 装饰器可见
我正在为何时或如何激活/使 MoveAdorner 可见而苦苦挣扎。
我尝试以下操作,但没有成功:在要装饰的元素中,我在 GotFocus 事件中添加了 Adorner。仅此还不够,所以我添加了对 InvalidateVisual() 的调用。但什么也没发生。有人提示如何使这些装饰器可见吗?
protected void MyUIElement_GotFocus( object sender, RoutedEventArgs e )
{
AdornerLayer layer = AdornerLayer.GetAdornerLayer( this );
layer.Add( new MoveAdorner( this ) );
layer.InvalidateVisual( );
}
澄清一下:装饰元素是一个控件,位于自定义 ItemsControl 的派生面板内。
MoveAdorner
派生自 Adorner
,只是在控件的顶部和底部绘制两个 Box。
谨致问候
i'm struggling a bit about when or how to activate / make visible a MoveAdorner.
I try the following but have no success: In the element that is to be adorned i add the Adorner in the GotFocus event. That alone did not suffice so i added a call to InvalidateVisual(). But nothing happens. Has anyone a hint on how to make those Adorners Visible?
protected void MyUIElement_GotFocus( object sender, RoutedEventArgs e )
{
AdornerLayer layer = AdornerLayer.GetAdornerLayer( this );
layer.Add( new MoveAdorner( this ) );
layer.InvalidateVisual( );
}
For Clarification: the adorned element is a Control that is positioned inside a derived Panel of a custom ItemsControl.
The MoveAdorner
derives from Adorner
and simply draws two Boxes on the top and bottom line of the control.
with kind regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,“获得/失去焦点”事件不太适合这种情况。想象一下您想要显示可以获得焦点的附加输入控件。
现在我已经连接到 LeftButtonUpEvent 并隐藏所有其他装饰器并且仅显示当前元素的装饰器。
此外,装饰器是根据要求按需添加的。该方法在要“装饰”的控件中定义。
}
In fact the Got/Lost Focus events are not very good for this situation. Imagine you want to show additional input controls that can get the focus.
Now i've hooked up into the LeftButtonUpEvent and Hide all other Adorners and only Showing the Adorner of the current element.
Also, the adorner is added on demand when requested. This method is defined in the Control that is to be "adorned".
}