0

The Circumstances

I'm building a plugin for a WPF application. The parent application has a ContentPresenter and my plugin returns a UserControl. When the parent app runs, it loads up my plugin and places my UserControl inside the ContentPresenter.

The Problem

The problem is that my UserControl is not resized to fit within the ContentPresenter, so when the ContentPresenter is too small to show everything, my UserControl is simply cut off. If the app is resized so that the ContentPresenter becomes bigger than my UserControl, then I get a bunch of whitespace around my UserControl.

Basically, I want my UserControl to act as if it was inside a DockPanel.

What I've Tried

Both the ContentPresenter and the UserControl have Horizontal and Vertical alignments set to Stretch already.

I can achieve the desired result if I wrap my UserControl in a ViewBox, but I don't really know if that's the right way to do it. It feels like I'm missing out on some basic layout principle (which might just be a holdover from my Winforms days). Is there any "proper" way to achieve a docking effect within a ContentPresenter element?

EDIT: I want to emphasize that this is not a ContentControl vs. ContentPresenter issue. I cannot change out the ContentPresenter element because it is part of the parent application. The only thing I can control is the contents of my own plugin which are being placed within the ContentPresenter element. The developers of the parent application might allow me LIMITED access to the ContentPresenter if I need to adjust a property by traversing up the visual tree at runtime, but they've already stated that they don't want plugins navigating outside of their own scope of controls. This isn't as much of a technical limitation as a their-terms-and-conditions-won't-allow-it limitation.

jhilgeman
  • 1,543
  • 10
  • 27
  • Possible duplicate of [What's the difference between ContentControl and ContentPresenter?](https://stackoverflow.com/questions/1287995/whats-the-difference-between-contentcontrol-and-contentpresenter) – Bizhan Jun 05 '18 at 21:38
  • I marked as duplicate because I think you should use a ContentControl instead of ContentPresenter. post the relevant code to the ContentPresenter if you disagree – Bizhan Jun 05 '18 at 21:39
  • I'm not the developer for the parent application, so I'm stuck with ContentPresenter. The parent app developers use other functionality of ContentPresenter for their own purposes. All I can control is the contents of my plugin. – jhilgeman Jun 05 '18 at 21:53
  • Is every Element in your `UserControl` designed to change its Size when the `UserControl` Size changes? If a `Grid` inside your `UserControl` has a fixed Size, the `UserControl` can stretch and shrink, but the `Grid`stays the same. – LittleBit Jun 06 '18 at 06:57
  • Yes it is designed to resize, and the resizing has been tested successfully outside the parent app. – jhilgeman Jun 06 '18 at 13:04

0 Answers0