如何使 WPF 装饰器可见

发布于 2024-10-05 02:42:05 字数 566 浏览 0 评论 0原文

我正在为何时或如何激活/使 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぶ宁プ宁ぶ 2024-10-12 02:42:05

事实上,“获得/失去焦点”事件不太适合这种情况。想象一下您想要显示可以获得焦点的附加输入控件。

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

此外,装饰器是根据要求按需添加的。该方法在要“装饰”的控件中定义。

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

}

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

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文