1

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

4

1 回答 1

0

事实上,Got/Lost Focus 事件对于这种情况并不是很好。想象一下,您想要显示可以获取焦点的其他输入控件。

现在我已经连接到 LeftButtonUpEvent 并隐藏所有其他 Adorner 并且只显示当前元素的 Adorner。

此外,装饰器会在请求时按需添加。此方法在要“装饰”的控件中定义。

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;
      }
  }

}

于 2010-12-03T10:08:38.587 回答