Skip to content

Commit e4af15b

Browse files
authored
Fix: Fixed a bug where dropdown flyouts opened in the wrong location (#15246)
1 parent 8781bfa commit e4af15b

File tree

6 files changed

+69
-25
lines changed

6 files changed

+69
-25
lines changed

src/Files.App/App.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<Application
33
x:Class="Files.App.App"
44
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:uc="using:Files.App.UserControls">
67

78
<Application.Resources>
89
<ResourceDictionary>
@@ -30,6 +31,8 @@
3031
<Setter Target="HighContrastAdjustment" Value="None" />
3132
</Style>
3233

34+
<Style BasedOn="{StaticResource DefaultComboBoxStyle}" TargetType="uc:ComboBoxEx" />
35+
3336
<ResourceDictionary.MergedDictionaries>
3437
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
3538

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
using Microsoft.UI.Xaml;
5+
using Microsoft.UI.Xaml.Controls;
6+
using Windows.Foundation;
7+
8+
namespace Files.App.UserControls
9+
{
10+
public class ComboBoxEx : ComboBox
11+
{
12+
double _cachedWidth;
13+
14+
protected override void OnDropDownOpened(object e)
15+
{
16+
Width = _cachedWidth;
17+
18+
base.OnDropDownOpened(e);
19+
}
20+
21+
protected override void OnDropDownClosed(object e)
22+
{
23+
Width = double.NaN;
24+
25+
base.OnDropDownClosed(e);
26+
}
27+
28+
protected override Size MeasureOverride(Size availableSize)
29+
{
30+
var baseSize = base.MeasureOverride(availableSize);
31+
32+
if (baseSize.Width != 64)
33+
_cachedWidth = baseSize.Width;
34+
35+
return baseSize;
36+
}
37+
}
38+
}

src/Files.App/Views/Settings/AppearancePage.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
xmlns:local="using:Files.App.UserControls.Settings"
1111
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1212
xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls"
13+
xmlns:uc="using:Files.App.UserControls"
1314
xmlns:vm="using:Files.App.ViewModels.Settings"
1415
xmlns:wctconverters="using:CommunityToolkit.WinUI.UI.Converters"
1516
mc:Ignorable="d">
@@ -108,7 +109,7 @@
108109
<local:SettingsBlockControl.Icon>
109110
<FontIcon Glyph="&#xE790;" />
110111
</local:SettingsBlockControl.Icon>
111-
<ComboBox
112+
<uc:ComboBoxEx
112113
x:Name="ThemeChooser"
113114
AutomationProperties.Name="{helpers:ResourceString Name=SettingsAppearanceTheme}"
114115
ItemsSource="{x:Bind ViewModel.Themes, Mode=OneWay}"
@@ -120,7 +121,7 @@
120121
<local:SettingsBlockControl.Icon>
121122
<FontIcon Glyph="&#xEF1F;" />
122123
</local:SettingsBlockControl.Icon>
123-
<ComboBox
124+
<uc:ComboBoxEx
124125
AutomationProperties.Name="{helpers:ResourceString Name=BackdropMaterial}"
125126
ItemsSource="{x:Bind ViewModel.BackdropMaterialTypes.Values}"
126127
SelectedItem="{x:Bind ViewModel.SelectedBackdropMaterial, Mode=TwoWay}" />

src/Files.App/Views/Settings/FoldersPage.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:helpers="using:Files.App.Helpers"
88
xmlns:local="using:Files.App.UserControls.Settings"
99
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10+
xmlns:uc="using:Files.App.UserControls"
1011
xmlns:vm="using:Files.App.ViewModels.Settings"
1112
mc:Ignorable="d">
1213

@@ -163,11 +164,11 @@
163164
<FontIcon Glyph="&#xE74D;" />
164165
</local:SettingsBlockControl.Icon>
165166

166-
<ComboBox AutomationProperties.Name="{helpers:ResourceString Name=ShowConfirmationWhenDeletingItems}" SelectedIndex="{x:Bind ViewModel.SelectedDeleteConfirmationPolicyIndex, Mode=TwoWay}">
167+
<uc:ComboBoxEx AutomationProperties.Name="{helpers:ResourceString Name=ShowConfirmationWhenDeletingItems}" SelectedIndex="{x:Bind ViewModel.SelectedDeleteConfirmationPolicyIndex, Mode=TwoWay}">
167168
<ComboBoxItem Content="{helpers:ResourceString Name=Always}" />
168169
<ComboBoxItem Content="{helpers:ResourceString Name=PermanentDeletionOnly}" />
169170
<ComboBoxItem Content="{helpers:ResourceString Name=Never}" />
170-
</ComboBox>
171+
</uc:ComboBoxEx>
171172
</local:SettingsBlockControl>
172173

173174
<!-- File Extension Warning -->

src/Files.App/Views/Settings/GeneralPage.xaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@
4444
<local:SettingsBlockControl.Icon>
4545
<FontIcon Glyph="&#xF2B7;" />
4646
</local:SettingsBlockControl.Icon>
47-
<ComboBox
47+
<uc:ComboBoxEx
4848
x:Name="AppLanguagesComboBox"
4949
HorizontalAlignment="Left"
5050
AutomationProperties.Name="{helpers:ResourceString Name=Language}"
5151
ItemsSource="{x:Bind ViewModel.AppLanguages}"
5252
SelectedIndex="{x:Bind ViewModel.SelectedAppLanguageIndex, Mode=TwoWay}">
53-
<ComboBox.ItemTemplate>
53+
<uc:ComboBoxEx.ItemTemplate>
5454
<DataTemplate x:DataType="vm:AppLanguageItem">
5555
<TextBlock Text="{x:Bind LanguageName}" />
5656
</DataTemplate>
57-
</ComboBox.ItemTemplate>
58-
</ComboBox>
57+
</uc:ComboBoxEx.ItemTemplate>
58+
</uc:ComboBoxEx>
5959
</local:SettingsBlockControl>
6060

6161
<!-- Date settings -->
@@ -66,13 +66,13 @@
6666
<local:SettingsBlockControl.Icon>
6767
<FontIcon Glyph="&#xEC92;" />
6868
</local:SettingsBlockControl.Icon>
69-
<ComboBox
69+
<uc:ComboBoxEx
7070
x:Name="DateFormatChooser"
7171
Grid.Column="1"
7272
AutomationProperties.Name="{helpers:ResourceString Name=DateFormat}"
7373
ItemsSource="{x:Bind ViewModel.DateFormats}"
7474
SelectedIndex="{x:Bind ViewModel.SelectedDateTimeFormatIndex, Mode=TwoWay}">
75-
<ComboBox.ItemTemplate>
75+
<uc:ComboBoxEx.ItemTemplate>
7676
<DataTemplate x:DataType="vm:DateTimeFormatItem">
7777
<StackPanel Orientation="Vertical">
7878
<TextBlock Text="{x:Bind Label}" />
@@ -88,16 +88,16 @@
8888
Visibility="{Binding IsDropDownOpen, ElementName=DateFormatChooser}" />
8989
</StackPanel>
9090
</DataTemplate>
91-
</ComboBox.ItemTemplate>
92-
</ComboBox>
91+
</uc:ComboBoxEx.ItemTemplate>
92+
</uc:ComboBoxEx>
9393
</local:SettingsBlockControl>
9494

9595
<!-- Startup settings -->
9696
<local:SettingsBlockControl Title="{helpers:ResourceString Name=StartupSettings}" HorizontalAlignment="Stretch">
9797
<local:SettingsBlockControl.Icon>
9898
<FontIcon Glyph="&#xE7E8;" />
9999
</local:SettingsBlockControl.Icon>
100-
<ComboBox AutomationProperties.Name="{helpers:ResourceString Name=StartupSettings}" SelectedIndex="{x:Bind ViewModel.SelectedStartupSettingIndex, Mode=OneWay}">
100+
<uc:ComboBoxEx AutomationProperties.Name="{helpers:ResourceString Name=StartupSettings}" SelectedIndex="{x:Bind ViewModel.SelectedStartupSettingIndex, Mode=OneWay}">
101101
<ComboBoxItem Content="{helpers:ResourceString Name=SettingsOnStartupOpenANewTab/Content}" IsSelected="{x:Bind ViewModel.OpenNewTabPageOnStartup, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
102102

103103
<ComboBoxItem Content="{helpers:ResourceString Name=SettingsOnStartupContinueWhereYouLeftOff/Content}" IsSelected="{x:Bind ViewModel.ContinueLastSessionOnStartUp, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
@@ -106,7 +106,7 @@
106106
x:Name="OpenSpecificPage"
107107
Content="{helpers:ResourceString Name=SettingsOnStartupOpenASpecificPage/Content}"
108108
IsSelected="{x:Bind ViewModel.OpenASpecificPageOnStartup, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
109-
</ComboBox>
109+
</uc:ComboBoxEx>
110110
<local:SettingsBlockControl.ExpandableContent>
111111
<StackPanel>
112112
<Grid

src/Files.App/Views/Settings/LayoutPage.xaml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
xmlns:helpers="using:Files.App.Helpers"
99
xmlns:local="using:Files.App.UserControls.Settings"
1010
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
11+
xmlns:uc="using:Files.App.UserControls"
1112
xmlns:vm="using:Files.App.ViewModels.Settings"
1213
mc:Ignorable="d">
1314

@@ -65,14 +66,14 @@
6566
<FontIcon Glyph="&#xE8BA;" />
6667
</local:SettingsBlockControl.Icon>
6768

68-
<ComboBox AutomationProperties.Name="{helpers:ResourceString Name=LayoutType}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultLayoutModeIndex, Mode=TwoWay}">
69+
<uc:ComboBoxEx AutomationProperties.Name="{helpers:ResourceString Name=LayoutType}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultLayoutModeIndex, Mode=TwoWay}">
6970
<ComboBoxItem Content="{helpers:ResourceString Name=Details}" />
7071
<ComboBoxItem Content="{helpers:ResourceString Name=List}" />
7172
<ComboBoxItem Content="{helpers:ResourceString Name=Tiles}" />
7273
<ComboBoxItem Content="{helpers:ResourceString Name=Columns}" />
7374
<ComboBoxItem Content="{helpers:ResourceString Name=Grid}" />
7475
<ComboBoxItem Content="{helpers:ResourceString Name=Adaptive}" IsEnabled="{x:Bind ViewModel.SyncFolderPreferencesAcrossDirectories, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}" />
75-
</ComboBox>
76+
</uc:ComboBoxEx>
7677
</local:SettingsBlockControl>
7778

7879
<!-- Sorting & grouping -->
@@ -88,14 +89,14 @@
8889
<FontIcon Glyph="&#xE8CB;" />
8990
</local:SettingsBlockControl.Icon>
9091

91-
<ComboBox AutomationProperties.Name="{helpers:ResourceString Name=SortBy}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultSortingIndex, Mode=TwoWay}">
92+
<uc:ComboBoxEx AutomationProperties.Name="{helpers:ResourceString Name=SortBy}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultSortingIndex, Mode=TwoWay}">
9293
<ComboBoxItem Content="{helpers:ResourceString Name=Name}" />
9394
<ComboBoxItem Content="{helpers:ResourceString Name=DateModifiedLowerCase}" />
9495
<ComboBoxItem Content="{helpers:ResourceString Name=DateCreated}" />
9596
<ComboBoxItem Content="{helpers:ResourceString Name=Size}" />
9697
<ComboBoxItem Content="{helpers:ResourceString Name=Type}" />
9798
<ComboBoxItem Content="{helpers:ResourceString Name=Tag}" />
98-
</ComboBox>
99+
</uc:ComboBoxEx>
99100
<local:SettingsBlockControl.ExpandableContent>
100101
<StackPanel>
101102
<!-- Sort in Descending order -->
@@ -108,11 +109,11 @@
108109

109110
<!-- Sort Priority -->
110111
<local:SettingsBlockControl Title="{helpers:ResourceString Name=SortPriority}" HorizontalAlignment="Stretch">
111-
<ComboBox AutomationProperties.Name="{helpers:ResourceString Name=SortPriority}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultSortPriorityIndex, Mode=TwoWay}">
112+
<uc:ComboBoxEx AutomationProperties.Name="{helpers:ResourceString Name=SortPriority}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultSortPriorityIndex, Mode=TwoWay}">
112113
<ComboBoxItem Content="{helpers:ResourceString Name=SortFoldersFirst}" />
113114
<ComboBoxItem Content="{helpers:ResourceString Name=SortFilesFirst}" />
114115
<ComboBoxItem Content="{helpers:ResourceString Name=SortFilesAndFoldersTogether}" />
115-
</ComboBox>
116+
</uc:ComboBoxEx>
116117
</local:SettingsBlockControl>
117118
</StackPanel>
118119
</local:SettingsBlockControl.ExpandableContent>
@@ -124,15 +125,15 @@
124125
<FontIcon Glyph="&#xF168;" />
125126
</local:SettingsBlockControl.Icon>
126127

127-
<ComboBox AutomationProperties.Name="{helpers:ResourceString Name=GroupBy}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultGroupingIndex, Mode=TwoWay}">
128+
<uc:ComboBoxEx AutomationProperties.Name="{helpers:ResourceString Name=GroupBy}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultGroupingIndex, Mode=TwoWay}">
128129
<ComboBoxItem Content="{helpers:ResourceString Name=None}" />
129130
<ComboBoxItem Content="{helpers:ResourceString Name=Name}" />
130131
<ComboBoxItem Content="{helpers:ResourceString Name=DateModifiedLowerCase}" />
131132
<ComboBoxItem Content="{helpers:ResourceString Name=DateCreated}" />
132133
<ComboBoxItem Content="{helpers:ResourceString Name=Size}" />
133134
<ComboBoxItem Content="{helpers:ResourceString Name=Type}" />
134135
<ComboBoxItem Content="{helpers:ResourceString Name=Tag}" />
135-
</ComboBox>
136+
</uc:ComboBoxEx>
136137
<local:SettingsBlockControl.ExpandableContent>
137138
<StackPanel>
138139
<!-- Group in Descending order -->
@@ -146,14 +147,14 @@
146147

147148
<!-- Group by date unit -->
148149
<local:SettingsBlockControl Title="{helpers:ResourceString Name=GroupByDateUnit}" HorizontalAlignment="Stretch">
149-
<ComboBox
150+
<uc:ComboBoxEx
150151
AutomationProperties.Name="{helpers:ResourceString Name=GroupByDateUnit}"
151152
IsEnabled="{x:Bind ViewModel.IsGroupByDate, Mode=OneWay}"
152153
SelectedIndex="{x:Bind ViewModel.SelectedDefaultGroupByDateUnitIndex, Mode=TwoWay}">
153154
<ComboBoxItem Content="{helpers:ResourceString Name=Year}" />
154155
<ComboBoxItem Content="{helpers:ResourceString Name=Month}" />
155156
<ComboBoxItem Content="{helpers:ResourceString Name=Day}" />
156-
</ComboBox>
157+
</uc:ComboBoxEx>
157158
</local:SettingsBlockControl>
158159
</StackPanel>
159160
</local:SettingsBlockControl.ExpandableContent>

0 commit comments

Comments
 (0)