Skip to content

Custom Control drawing in front of children #16433

Answered by BAndysc
Arcnor asked this question in Q&A
Discussion options

You must be logged in to vote

Example code:

public class CustomContentControl : ContentControl
{
    private CustomControlControlRenderer renderer;

    protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
    {
        base.OnApplyTemplate(e);
        renderer = e.NameScope.Get<CustomControlControlRenderer>("PART_Renderer");
        renderer.OnRender += RenderOverlay;
    }

    public void RenderOverlay(DrawingContext context)
    {
      // do drawing here
    }
}

public class CustomControlControlRenderer : Control
{
    public event Action<DrawingContext> OnRender;

    public override void Render(DrawingContext context)
    {
        OnRender?.Invoke(context);
    }
}

and resources:

<ControlTheme…

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
1 reply
@Arcnor
Comment options

Comment options

You must be logged in to vote
5 replies
@Arcnor
Comment options

@BAndysc
Comment options

@Arcnor
Comment options

@BAndysc
Comment options

Answer selected by Arcnor
@Arcnor
Comment options

Comment options

You must be logged in to vote
1 reply
@BAndysc
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants