开发者

How to make WPF Adorner visible

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 l开发者_JS百科ine of the control.

with kind regards


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".

private void ShowAdorner( ) {
  Owner.HideAppointmentAdorners( );

  AdornerLayer layer = AdornerLayer.GetAdornerLayer( this );

  Adorner []adorners = layer.GetAdorners( this );

  if( adorners == null || adorners.Length == 0 )
  {
      layer.Add( new ResizingAdorner( this ) { Visibility = System.Windows.Visibility.Visible } );
  }
  else
  {
      for( int i = 0; i < adorners.Length; i++ )
      {
          adorners [ i ].Visibility = System.Windows.Visibility.Visible;
      }
  }

}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜