Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6745119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:09:58+00:00 2026-05-26T12:09:58+00:00

Is there a way to get the shape of a control and convert it

  • 0

Is there a way to get the shape of a control and convert it into a Geometry object?

I have the following situation: In a WPF application a popup will be shown. This popup is no windows, it’s a control, that will get visible. The rest of the application will get darker as a gray layer is above the application.

Now the problem is that this gray layer is also above the popup itself which is caused by the design of the application plus the element that was clicked and opened the popup should also not be hidden by the layer. I decided to attach a clipping geometry to the gray layer which is fine, but I have to detect all forms and paths that I don’t want to hide by myself.

So to get back to my question: Is there a way to get the shape of a control and convert it into a Geometry object? E.g. I found ways to get the VisualBrush of a control but also cannot convert that – or just do not see how it is possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:09:59+00:00Added an answer on May 26, 2026 at 12:09 pm

    you could do it this way:
    Remove the button from the visual tree and place it on the adorner.
    When the adorner closes attach it to the original parent again.
    I think this is much more flexible than clipping any geometries and makes it much more flexible (you could e.g. place complex content like usercontrols on the adorner)

    The following example uses a Panel as container for the button.

    The Xaml (Window):

    <Grid Margin="50" x:Name="myGrid" Background="LightBlue">
    <Button x:Name="myButton" Width="80" Height="30" Click="myButton_Click">Show popup</Button>
    

    Code Behind:
    private FrameworkElementAdorner _adorner;
    private Panel _originalParent;

    private void myButton_Click(object sender, RoutedEventArgs e)
    {
      if (_adorner == null)
      {
        _adorner = new FrameworkElementAdorner(myGrid);
      }
    
      // remove the button from the parent panel and attach it to the adorner
      // otherwise remove from adorner and attach to original parent again
      if (_adorner.IsVisible)
      {
        AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(myGrid);
        adornerLayer.Remove(_adorner);
    
        Panel parent = VisualTreeHelper.GetParent(myButton) as Panel;
        if (parent != null)
        {
          parent.Children.Remove(myButton);
        }
        _originalParent.Children.Add(myButton);
      }
      else
      {
        _originalParent = VisualTreeHelper.GetParent(myButton) as Panel;
        if (_originalParent != null)
        {
          _originalParent.Children.Remove(myButton);
        }
    
        // Create the Adorner with the original button in it
        _adorner.Child = CreateAdornerContent(myButton);
    
        AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(myGrid);
        adornerLayer.Add(_adorner);
      }
    }
    
    /// <summary>
    /// Creates some dummy content for the adorner
    /// </summary>
    private FrameworkElement CreateAdornerContent(Button myButton)
    {
      Grid g = new Grid();
      g.Background = new SolidColorBrush(Colors.Yellow);
    
      TextBlock tb = new TextBlock();
      tb.Text = "I am the Adorner";
    
      g.Children.Add(tb);
      g.Children.Add(myButton);
      return g;
    }
    

    And here the simple adorner which just displays a frameworkElement:
    class FrameworkElementAdorner : Adorner
    {
    private FrameworkElement _child;

    public FrameworkElementAdorner(UIElement adornedElement)
      : base(adornedElement)
    {
    }
    
    protected override int VisualChildrenCount
    {
      get
      {
        return 1;
      }
    }
    
    protected override Visual GetVisualChild(int index)
    {
      if (index != 0) throw new ArgumentOutOfRangeException();
      return _child;
    }
    
    public FrameworkElement Child
    {
      get
      {
        return _child;
      }
      set
      {
        if (_child != null)
        {
          RemoveVisualChild(_child);
        }
        _child = value;
        if (_child != null)
        {
          AddVisualChild(_child);
        }
      }
    }
    
    protected override Size ArrangeOverride(Size finalSize)
    {
      _child.Arrange(new Rect(new Point(0, 0), finalSize));
      return new Size(_child.ActualWidth, _child.ActualHeight);
    }
    

    }

    I can also upload the full sln if you like. Is this possible here somehow?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to get the previous hash using the history object ?I
Is there any way I can get a share picker like the one seen
Is there way to get file from windows xp command prompt? I tried to
is there way how to get name ov event from Lambda expression like with
Is there a way to get the item pointed at by an iterator in
Is there a way to get distance between two objects in meters? I'm trying
Is there a way to get the path to where WordPress is installed? I
Is there a way to get the actual columns name with ActiveRecord? When I
Is there a way to get HTML contents from TinyMCE editor using jQuery so
Is there any way to get direct URL to a JSF bean action method?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.