microsoft / microsoft/microsoft-ui-xaml

Use CommandBarFlyout in page resource, throw Value does not fall within the expected range

Open
#10,170 4 comments 0 reactions 0 assignees View on GitHub
area-CommandBarFlyout bug team-Controls
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

The commandBarFlyout.ShowAt() function throw an Exception: Value does not fall within the expected range.
The CommandBarFlyout Control is defined in page resources:
```xaml














```
Here's the invoke event:
```csharp
private void GridView_RightTapped(object sender, Microsoft.UI.Xaml.Input.RightTappedRoutedEventArgs e)
{
if (sender is Grid grid && grid.DataContext is BlueprintInfoViewData blueprintInfoViewData)
{
commandBarFlyout.ShowAt(grid);
}
}
```
This event is binding to the GridView's RightTapped event.

I have tried to set the XamlRoot in CommandBarFlyout, but it doesn't work.

### Steps to reproduce the bug

Defined the CommandBarFlyItem in page resources, and binding the GridView's RightTapped event.
The right click anywhere in gridView control, then the exception throw.

### Expected behavior

_No response_

### Screenshots

![Image](https://github.com/user-attachments/assets/ef224085-3686-4479-bd20-07994ab4ec3a)

### NuGet package version

WinUI 3 - Windows App SDK 1.6.2: 1.6.241106002

### Windows version

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

The report names CommandBarFlyout.ShowAt(grid) in the GridView_RightTapped handler and uses Windows App SDK 1.6.2. Reproduce the page-resource scenario first, then trace the CommandBarFlyout implementation and existing tests; done means the handler no longer throws "Value does not fall within the expected range" for the supplied markup.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.