✅ 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.
<Base:AbstractVisualConversationTabCtrl
x:Class="BestChat.IRC.Global.View.Ctrls.ConversationViewCtrl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BestChat.IRC.Global.View.Ctrls"
xmlns:Base="clr-namespace:BestChat.GUI.Ctrls;assembly=BestChat.GUI.Ctrls"
xmlns:data="BestChat.Platform.Conversations;Assembly=BestChat.Platform.Conversations"
mc:Ignorable="d"
xmlns:CalcBinding="clr-namespace:CalcBinding;assembly=CalcBinding">
<Base:AbstractVisualConversationTabCtrl.Resources>
<Style
x:Key="ChkBoxStyle"
TargetType="CheckBox"
BasedOn="{StaticResource {x:Static ToolBar.ToggleButtonStyleKey}}" />
</Base:AbstractVisualConversationTabCtrl.Resources>
<DockPanel>
<WrapPanel
x:Name="wrapDataBar"
DockPanel.Dock="Top" />
<Border
Background="Black" />
</DockPanel>
</Base:AbstractVisualConversationTabCtrl>
<Base:AbstractVisualConversationTabCtrl
x:Class="BestChat.IRC.Global.View.Ctrls.ConversationViewCtrl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BestChat.IRC.Global.View.Ctrls"
xmlns:Base="clr-namespace:BestChat.GUI.Ctrls;assembly=BestChat.GUI.Ctrls"
xmlns:data="BestChat.Platform.Conversations;Assembly=BestChat.Platform.Conversations"
mc:Ignorable="d"
xmlns:CalcBinding="clr-namespace:CalcBinding;assembly=CalcBinding">
<Base:AbstractVisualConversationTabCtrl.Resources>
<Style
x:Key="ChkBoxStyle"
TargetType="CheckBox"
BasedOn="{StaticResource {x:Static ToolBar.ToggleButtonStyleKey}}" />
</Base:AbstractVisualConversationTabCtrl.Resources>
<DockPanel>
<WrapPanel
x:Name="wrapDataBar"
DockPanel.Dock="Top" />
<Border
Background="Black" />
</DockPanel>
</Base:AbstractVisualConversationTabCtrl>
1 Reply
Will Pittenger
Will PittengerOP13mo ago
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.
Want results from more Discord servers?
Add your server