Skip to content

How a derived class of FrameworkElement creates visual children OR renders #646

@verelpode

Description

@verelpode

Thanks for documenting FrameworkElement. Could you please explain how a derived class of FrameworkElement (or UIElement) can create visual child elements and/or render itself? How to create visual child elements without using a control template? I do realize that the documentation says "Typically, you don't derive classes directly from FrameworkElement", but occasionally it is necessary to derive directly from FrameworkElement, thus it would be greatly appreciated if you could explain how to do this, in particular the rendering or visual children part.

I understand that one option is to derive from Control instead of FrameworkElement and then use a control template, but sometimes templates are not the right solution for a particular UI element class, therefore how can we derive directly from FrameworkElement?

For comparison, in the older WPF-Desktop, a derived class could create visual child elements by overriding the following members, but these members do not exist in UWP, therefore how is it done in UWP?

  • System.Windows.FrameworkElement.VisualChildrenCount
  • System.Windows.FrameworkElement.GetVisualChild(int)

Also in WPF-Desktop, a class could render itself by overriding System.Windows.UIElement.OnRender(System.Windows.Media.DrawingContext) but this method does not exist in UWP, therefore how is it done in UWP?

Thank you!


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Labels

Pri2Topic is in the second 25% of page views for the repo.area-xamlXAML-related feedback.doc-bugTopic has missing, outdated, unclear, confusing info, or has broken functionality.eng-triagedIssue has been triaged by engineering team responsible.windows/prodTopic product is Windows-related.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions