✅ WPF Custom control should have contents as DockPanel, but it shows up at runtime as ScrollViewer
I have a
UserControl
I'm implementing with the source shown below. When I check my custom controls Content
property, the value is a ScrollViewer
. What's going on? I expected a DockPanel
.
1 Reply
I'm debating trying to convert the
WrapPanel
into a ItemsControl
. The catch is I'd need to create a Template Selector. I'm letting it bake for a while.
It's now coded and compiles, but haven't gotten to testing it yet. Need to put a few more pieces in first.
Well, the code runs just fine. Took two ItemsControl
instances each needing a Template Selector. However, I still have the Live Property Explorer reporting the contents of my user control is a ScrollViewer
rather than a DockPanel
. The problem is I'm trying to figure out why the controls I was adding on the fly (now done with the ItemsControl
weren't showing up.
Looks like my DockPanel
was created, but not added to the tree. I checked the VisualParent
property. It was null
.
Well, I'm giving up for now and calling it a night.
I finally figured out what was going on. A couple months ago,, I wrote a base class (that I derived from a couple times) that created the ScrollViewer
. I found it by searching for "ScrollViewer" in my files. Until a few hours ago, I was thinking it would appear only in a XAML file. But this was in a class that didn't have a XAML as it was abstract
and I was going to have the derived class provide the XAML. But for some strange reason I don't remember, I put the ScrollViewer
in the CS file's OnInitialized
which promptly erased the contents from the XAML. In some situations, I'll want all views to have a ScrollViewer
as the content of the window with its content provided provided by an implementation. But in this situation, the derived class will be providing what you could think of as the "non-client" area never mind this isn't a Window
. Basically, some versions will be adding a bar along the top. At least I know what was going on. I'm considering moving things around a bit.
As is, I put a Ctnts
property into the abstract
class and mapped it to the ScrollViewer
's Content
property. I may simply change that so there's a panel that's hidden unless it receives content. What I called Ctnts
would be renamed Hdr
and mapped to the new panel's Content
property.
The branch of the control's derived classes I was working on will generate a list of contents for the ScrollViewer
as was always the plan.