microsoft / microsoft/microsoft-ui-xaml

VisualTreeHelper unable to traverse TeachingTip content

Open
#10,857 2 comments 1 reaction 0 assignees View on GitHub
area-TeachingTip bug
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

I am doing some customization using attached `DependencyProperty`, so I attached a `Loaded` event handler to a `TeachingTip` to traverse it with `VisualTreeHelper`, but it is unable to traverse the visual tree of it, giving no useful information.

### Why is this important?

This should work

### Steps to reproduce the bug
I have a `TeachingTip` defined in xaml
```xml
Click to open tip

```

0. Add a helper function to traverse a control and print it type name and name
```cpp
static void printVisualTree(winrt::Microsoft::UI::Xaml::FrameworkElement const& element)
{
if (!element)
return;

OutputDebugString(std::format(L"{}: {}\n", winrt::get_class_name(element), element.Name()).data());

auto const numChild = winrt::Microsoft::UI::Xaml::Media::VisualTreeHelper::GetChildrenCount(element);
for (auto i = 0; i < numChild; ++i)
{
printVisualTree(winrt::Microsoft::UI::Xaml::Media::VisualTreeHelper::GetChild(element, i).as());
}
}
```

1. Print out the visual tree in both `Loaded` and `LayoutUpdated` event

```cpp
void MainWindow::MyTip_Loaded(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
auto teachingTip = sender.as();
OutputDebugString(L"==============Loaded==========\n");
printVisualTree(teachingTip);
}

void MainWindow::MyTip_LayoutUpdated(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::Foundation::IInspectable const& e)
{
OutputDebugString(L"==============Layout Updated==========\n");
printVisualTree(MyTip());
}
```

### Actual behavior
Gives
```
==============Layout Updated==========
Microsoft.UI.Xaml.Controls.TeachingTip: MyTip
Microsoft.UI.Xaml.Controls.Border: Container
==============Loaded==========
Microsoft.UI.Xaml.Controls.TeachingTip: MyTip
Microsoft.UI.Xaml.Controls.Border: Container
```

### Expected behavior

_No response_

### Screenshots

_No response_

### NuGet package version

WinUI 3 - Windows App SDK 1.8.2: 1.8.251003001

### Windows version

Windows 11 (24H2): Build 26100

### Additional context
[Full repro](https://github.com/HO-COOH/WinUI-Bug/tree/main/33-TeachingTipNullContent)

Contributor guide

Open the contributing guide

Research direction

Run the linked full repro and inspect the TeachingTip behavior in the Loaded and LayoutUpdated handlers using VisualTreeHelper. Start with the TeachingTip, its Container Border, and the WinUI 3 Windows App SDK 1.8.2 context; done means the expected visual-tree traversal is established and the reported inability to reach the TeachingTip content is resolved or clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.