Repository navigation
Description
Current behavior 🐛
Selector.GetItemsHostOrientations() only recognizes StackPanel and IOrientedPanel. ItemsStackPanel does not implement IOrientedPanel, so when a ListView/ComboBox uses a horizontal ItemsStackPanel (Orientation="Horizontal"), the method still reports Vertical for both the physical and logical orientation.
// Selector.cs, GetItemsHostOrientations()
// TODO Uno: This implementation is simplified, should be ported from WinUI
if (panel is StackPanel sp) { ... }
else if (panel is IOrientedPanel orientedPanel) { ... } // only VariableSizedWrapGrid implements it
// otherwise (Vertical, Vertical)Expected behavior 🎯
Like WinUI, a horizontal ItemsStackPanel reports Horizontal/Horizontal. In WinUI ItemsStackPanel implements IOrientedPanel: get_LogicalOrientation returns Orientation and get_PhysicalOrientation forwards to it. ItemsWrapGrid does the same, with the physical orientation being the opposite of Orientation.
How to reproduce it (as minimally and precisely as possible) 🔬
GetItemsHostOrientations is protected virtual on the public Selector, so it can be observed from a subclass:
- Create a
ListViewsubclass that exposes the method:public class ProbeListView : ListView { public (Orientation Physical, Orientation Logical) Probe() => GetItemsHostOrientations(); }
- Put it in a loaded page:
<local:ProbeListView x:Name="lv"> <local:ProbeListView.ItemsPanel> <ItemsPanelTemplate> <ItemsStackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </local:ProbeListView.ItemsPanel> <x:String>A</x:String> <x:String>B</x:String> </local:ProbeListView>
- After the control is loaded, call
lv.Probe(). - Result:
(Vertical, Vertical). Expected:(Horizontal, Horizontal).
Note: this was confirmed by reading the source on master (permalinks below), not by running the snippet above.
Impact
Selector.HandleNavigationKeycomputesisVerticalfrom this method. Today the visible effect is small:ComboBoxonly reaches it for Home/End/PageUp/PageDown and the gamepad triggers, andNavigateByPageis still aTODO. The gamepad left/right trigger paging uses the wrong axis for a horizontalItemsStackPanel.- Any further port of WinUI code that calls
GetPanelOrientations/GetItemsHostOrientations(drag-over zones and keyboard reorder inListViewBase) will get the wrong axis. ItemsWrapGridis not implemented in Uno, so onlyItemsStackPanelis affected for now.
Workaround 🛠️
Switch on ItemsPanelRoot (ItemsStackPanel.Orientation) before falling back to GetItemsHostOrientations().
Works on UWP/WinUI
Yes. WinUI's Selector::GetPanelOrientations queries IOrientedPanel, which ItemsStackPanel and ItemsWrapGrid implement.
Affected platforms 📱💻🖥️
All (the code is shared, not platform-specific).
Uno.Sdk version (and other relevant versions) 📦
master @ cc48541
IDE version 🧑💻
N/A
Anything else we need to know? 💬
WinUI parity is backed by the WinUI C++ sources (dxaml/xcp/dxaml/lib/): Selector::GetItemsHostOrientations / Selector::GetPanelOrientations in Selector_Partial.cpp, ItemsStackPanel::get_LogicalOrientation / get_PhysicalOrientation in ItemsStackPanel_Partial.cpp, and the IOrientedPanel interface entry in ItemsStackPanel.g.cpp.
Uno side (master cc48541):
uno/src/Uno.UI/UI/Xaml/Controls/Primitives/Selector.cs
Lines 825 to 844 in cc48541
protected virtual (Orientation PhysicalOrientation, Orientation LogicalOrientation) GetItemsHostOrientations() { // TODO Uno: This implementation is simplified, should be ported from WinUI var panel = ItemsPanelRoot; var logicalOrientation = Orientation.Vertical; var physicalOrientation = Orientation.Vertical; if (panel is StackPanel sp) { logicalOrientation = sp.Orientation; physicalOrientation = logicalOrientation; } else if (panel is IOrientedPanel orientedPanel) { logicalOrientation = orientedPanel.LogicalOrientation; physicalOrientation = orientedPanel.PhysicalOrientation; } return (physicalOrientation, logicalOrientation); uno/src/Uno.UI/UI/Xaml/Controls/Primitives/Selector.partial.mux.cs
Lines 185 to 205 in cc48541
internal void HandleNavigationKey( VirtualKey key, bool scrollViewport, ref int newFocusedIndex) { bool bInvertForRTL = false; bool isVertical = false; FlowDirection direction = FlowDirection.LeftToRight; Orientation physicalOrientation = Orientation.Vertical; int nCount = 0; var spItems = Items; nCount = spItems.Count; direction = FlowDirection; bInvertForRTL = (direction == FlowDirection.RightToLeft); (physicalOrientation, _ /*pLogicalOrientation*/) = GetItemsHostOrientations(); isVertical = (physicalOrientation == Orientation.Vertical); switch (key) { case VirtualKey.Left: internal override Orientation? PhysicalOrientation => Orientation;
Suggested fix: implement IOrientedPanel on ItemsStackPanel (both orientations return Orientation). ItemsStackPanel already has an internal PhysicalOrientation override on Panel that Selector does not use. Add a test that probes the method through a ListView subclass as above.
Activity
seragAhmed commentedon Oct 31, 2026
Hi! I'd like to work on this one.
Plan: make
ItemsStackPanelimplementIOrientedPanellike WinUI (LogicalOrientationreturnsOrientation,PhysicalOrientationforwards to it), soSelector.GetItemsHostOrientations()picks it up, and add tests for both orientations.fix: Implement IOrientedPanel on ItemsStackPanel (fixes unoplatform#2…
Merge pull request unoplatform#25855 from seragAhmed/fix/itemsstackpa…