-
Notifications
You must be signed in to change notification settings - Fork 772
Open
Labels
area-TeachingTipbugSomething isn't workingSomething isn't workingneeds-triageIssue needs to be triaged by the area ownersIssue needs to be triaged by the area owners
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
<Button x:Name="Button" Click="Button_Click">Click to open tip</Button>
<TeachingTip
x:Name="MyTip"
Loaded="MyTip_Loaded"
LayoutUpdated="MyTip_LayoutUpdated"
Content="Some tip"/>- Add a helper function to traverse a control and print it type name and name
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<winrt::Microsoft::UI::Xaml::FrameworkElement>());
}
}- Print out the visual tree in both
LoadedandLayoutUpdatedevent
void MainWindow::MyTip_Loaded(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
auto teachingTip = sender.as<winrt::Microsoft::UI::Xaml::Controls::TeachingTip>();
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
Metadata
Metadata
Assignees
Labels
area-TeachingTipbugSomething isn't workingSomething isn't workingneeds-triageIssue needs to be triaged by the area ownersIssue needs to be triaged by the area owners