microsoft / microsoft/microsoft-ui-xaml
Applying Composition translation on a FrameworkElement that also sets facade properties breaks hit testing
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
If you sets a `Translation` on a `FrameworkElement` in xaml, something like this:
```xml
```
And you try to get its backing `Visual` and translate it in code
```cpp
auto visual = winrt::Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::GetElementVisual(Source());
auto compositor = visual.Compositor();
if (translation)
{
translation.Direction(winrt::Microsoft::UI::Composition::AnimationDirection::Reverse);
visual.StartAnimation(L"Translation.XY", translation);
}
else
{
winrt::Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::SetIsTranslationEnabled(Source(), true);
translation = compositor.CreateVector2KeyFrameAnimation();
translation.InsertKeyFrame(0.0f, { 0.f, 0.f });
translation.InsertKeyFrame(1.0f, { 20.f, 20.f });
visual.StartAnimation(L"Translation.XY", translation);
}
```
It will break the hit testing quietly.
Doing the same thing in UWP you will get an exception
```
WinRT originate error - 0x80070005 : 'Access denied. Calling ElementCompositionPreview.GetElementVisual API is not allowed on this object at this time, as this object currently has the Translation property in use.'
```
### Why is this important?
This lacks of documentation is actually dated back to #4904 on UWP (which is 4+ years old btw), and is still not documented on winui3. And now the issue is even more obscure, as no errors get printed, but hit testing is broken.
### Steps to reproduce the bug
As OP.
### Actual behavior
_No response_
### Expected behavior
_No response_
### Screenshots
_No response_
### NuGet package version
WinUI 3 - Windows App SDK 1.8.3: 1.8.251106002
### Windows version
Windows 11 (24H2): Build 26100, Windows 10 (1809): Build 17763
### Additional context
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by checking the documentation for ElementCompositionPreview.GetElementVisual and SetIsTranslationEnabled against the XAML/C++ reproduction in this issue. Done when the relevant API guidance explains the interaction with the FrameworkElement Translation property, including the hit-testing consequence and the supported alternative.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- Half a day
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100