Skip to content

Commit 01db226

Browse files
Fix SplitView sample layout issue when pane is on the right side (#2056)
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> This PR updates the `SplitView` sample to switch layouts dynamically depending on the pane's placement (left or right). ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here. --> Fixes #322. ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> Manually tested. ## Screenshots (if appropriate): ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change)
1 parent 2c0b8b5 commit 01db226

File tree

2 files changed

+74
-8
lines changed

2 files changed

+74
-8
lines changed

WinUIGallery/Samples/ControlPages/SplitViewPage.xaml

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,45 @@
55
xmlns:controlPages="using:WinUIGallery.ControlPages"
66
xmlns:controls="using:WinUIGallery.Controls">
77
<Page.Resources>
8-
<DataTemplate x:Key="NavLinkItemTemplate" x:DataType="controlPages:NavLink">
9-
<StackPanel
8+
<DataTemplate
9+
x:Key="LeftIconNavLinkItemTemplate"
10+
x:DataType="controlPages:NavLink">
11+
<Grid
1012
Margin="2,0,0,0"
11-
AutomationProperties.Name="{x:Bind Label}"
12-
Orientation="Horizontal">
13-
<SymbolIcon Symbol="{x:Bind Symbol}" />
13+
AutomationProperties.Name="{x:Bind Label}">
14+
<Grid.ColumnDefinitions>
15+
<ColumnDefinition Width="Auto" />
16+
<ColumnDefinition Width="*" />
17+
</Grid.ColumnDefinitions>
18+
<SymbolIcon
19+
Grid.Column="0"
20+
Symbol="{x:Bind Symbol}" />
1421
<TextBlock
22+
Grid.Column="1"
1523
Margin="24,0,0,0"
1624
VerticalAlignment="Center"
1725
Text="{x:Bind Label}" />
18-
</StackPanel>
26+
</Grid>
27+
</DataTemplate>
28+
<DataTemplate
29+
x:Key="RightIconNavLinkItemTemplate"
30+
x:DataType="controlPages:NavLink">
31+
<Grid
32+
Margin="0,0,2,0"
33+
AutomationProperties.Name="{x:Bind Label}">
34+
<Grid.ColumnDefinitions>
35+
<ColumnDefinition Width="*" />
36+
<ColumnDefinition Width="Auto" />
37+
</Grid.ColumnDefinitions>
38+
<TextBlock
39+
Grid.Column="0"
40+
Margin="0,0,24,0"
41+
VerticalAlignment="Center"
42+
Text="{x:Bind Label}" />
43+
<SymbolIcon
44+
Grid.Column="1"
45+
Symbol="{x:Bind Symbol}" />
46+
</Grid>
1947
</DataTemplate>
2048
</Page.Resources>
2149

@@ -28,7 +56,7 @@
2856
CompactPaneLength="{x:Bind compactPaneLengthSlider.Value, Mode=OneWay}"
2957
DisplayMode="CompactOverlay"
3058
IsPaneOpen="{x:Bind togglePaneButton.IsChecked, Mode=TwoWay, Converter={StaticResource nullableBooleanToBooleanConverter}}"
31-
Width="400"
59+
MaxWidth="400"
3260
IsTabStop="False"
3361
OpenPaneLength="{x:Bind openPaneLengthSlider.Value, Mode=OneWay}"
3462
PaneBackground="{ThemeResource SystemControlBackgroundChromeMediumLowBrush}">
@@ -51,7 +79,6 @@
5179
VerticalAlignment="Stretch"
5280
IsItemClickEnabled="True"
5381
ItemClick="NavLinksList_ItemClick"
54-
ItemTemplate="{StaticResource NavLinkItemTemplate}"
5582
ItemsSource="{x:Bind NavLinks}"
5683
SelectionMode="Single" />
5784
</Grid>
@@ -79,6 +106,8 @@
79106
<ToggleButton
80107
x:Name="togglePaneButton"
81108
Content="IsPaneOpen"
109+
Checked="togglePaneButton_CheckedChanged"
110+
Unchecked="togglePaneButton_CheckedChanged"
82111
IsChecked="True" />
83112

84113
<ToggleSwitch
@@ -198,6 +227,18 @@
198227
</VisualState.Setters>
199228
</VisualState>
200229
</VisualStateGroup>
230+
<VisualStateGroup x:Name="NavLinkItemLayoutStates">
231+
<VisualState x:Name="LeftIconLayout">
232+
<VisualState.Setters>
233+
<Setter Target="NavLinksList.ItemTemplate" Value="{StaticResource LeftIconNavLinkItemTemplate}" />
234+
</VisualState.Setters>
235+
</VisualState>
236+
<VisualState x:Name="RightIconLayout">
237+
<VisualState.Setters>
238+
<Setter Target="NavLinksList.ItemTemplate" Value="{StaticResource RightIconNavLinkItemTemplate}" />
239+
</VisualState.Setters>
240+
</VisualState>
241+
</VisualStateGroup>
201242
</VisualStateManager.VisualStateGroups>
202243
</StackPanel>
203244
</Page>

WinUIGallery/Samples/ControlPages/SplitViewPage.xaml.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public ObservableCollection<NavLink> NavLinks
2727
public SplitViewPage()
2828
{
2929
this.InitializeComponent();
30+
this.Loaded += SplitViewPage_Loaded;
31+
}
32+
33+
private void SplitViewPage_Loaded(object sender, RoutedEventArgs e)
34+
{
35+
UpdateNavLinkItemLayout();
3036
}
3137

3238
private void NavLinksList_ItemClick(object sender, ItemClickEventArgs e)
@@ -45,6 +51,25 @@ private void PanePlacement_Toggled(object sender, RoutedEventArgs e)
4551
{
4652
splitView.PanePlacement = SplitViewPanePlacement.Left;
4753
}
54+
55+
UpdateNavLinkItemLayout();
56+
}
57+
58+
private void UpdateNavLinkItemLayout()
59+
{
60+
if (splitView.PanePlacement == SplitViewPanePlacement.Right)
61+
{
62+
VisualStateManager.GoToState(this, "RightIconLayout", false);
63+
}
64+
else
65+
{
66+
VisualStateManager.GoToState(this, "LeftIconLayout", false);
67+
}
68+
}
69+
70+
private void togglePaneButton_CheckedChanged(object sender, RoutedEventArgs e)
71+
{
72+
UpdateNavLinkItemLayout();
4873
}
4974

5075
private void displayModeCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)

0 commit comments

Comments
 (0)