question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TabControl - UserControls inside DataTemplates are not rendered

See original GitHub issue

When using DataTemplates in a TabControl, if the DataTemplate contains a UserControl, the UserControl won’t be displayed.

Example

<TabControl>
    <TabControl.DataTemplates>
      <DataTemplate DataType="vms:SampleViewModel">
        <StackPanel Orientation="Vertical">
          <TextBlock Text="SampleViewModel.."/>
          <local:SampleView />
        </StackPanel>
      </DataTemplate>
    </TabControl.DataTemplates>
    <TabItem Header="Tab 1 - Content from DataTemplate"><vms:SampleViewModel /></TabItem>
    <TabItem Header="Tab 2" Content="Content for item 2"/>
    <TabItem Header="Tab 3 - View without DataTemplate"><local:SampleView /> </TabItem>
</TabControl>

When I select Tab 1, it shows me my DataTemplate but any UserControl (local:SampleView) inside the DataTemplate is not displayed, it only shows the TextBlock If I select Tab 3, the UserControl (local:SampleView) is shown properly…

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ksignecommented, Jan 4, 2019

@braca In ContentPresenter.cs:249 replace if (newChild.Parent == null && TemplatedParent == null) to if (newChild.Parent == null) It will help though side effects are not clear yet.

0reactions
grokyscommented, Jan 5, 2019

@Gillibald yeah it’s really not obvious. I think there might be a better way…

Should be fixed by https://github.com/AvaloniaUI/Avalonia/pull/2218 btw.

Read more comments on GitHub >

github_iconTop Results From Across the Web

My UserControl isn't being rendered when used inside a ...
But if I try to use the UserControl in a DataTemplate it doesn't work. For example, if I have a DataTemplate like
Read more >
[Latest] NoesisGUI v3.2.1 - Page 2 - Forums
Fixed: TabControl content layout was not deterministic. Fixed: DataTemplate were not found when stored by type in a ResourceDictionary.
Read more >
Problem with TabControl Template and Binding in WPF.
I would like to put image in TabControl header using binding, but below code doesn't work. I would like to know why, and...
Read more >
MapView in ContentPresenter bug?
I was trying to display multiple viewmodels where the DataTemplate contains a MapView in an itemscontrol (TabControl), I discovered that the map ...
Read more >
How to use a Tab Control and Tab Items with MVVM in C# ...
Learn how to use a Tab Control and its corresponding tab items when using the MVVM pattern in C#. This tutorial will show...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found