Skip to content

Commit 5a6dcb6

Browse files
authored
Simplifies PaneControl code by removing unnecessary dynamic xaml. (#9120)
1 parent 60c0780 commit 5a6dcb6

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/Files.Uwp/UserControls/Pane/PaneControl.xaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7-
d:DesignWidth="400" d:DesignHeight="300" mc:Ignorable="d">
7+
d:DesignHeight="300"
8+
d:DesignWidth="400"
9+
mc:Ignorable="d">
810

9-
<Grid x:Name="Panel" />
11+
<ContentControl
12+
x:Name="Panel"
13+
HorizontalContentAlignment="Stretch"
14+
VerticalContentAlignment="Stretch" />
1015

1116
</UserControl>

src/Files.Uwp/UserControls/Pane/PaneControl.xaml.cs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,32 @@ namespace Files.Uwp.UserControls
88
{
99
public sealed partial class PaneControl : UserControl, IPane
1010
{
11-
public PanePositions Position { get; private set; } = PanePositions.None;
11+
private PaneContents content;
1212

13-
private IPaneSettingsService PaneService { get; } = Ioc.Default.GetService<IPaneSettingsService>();
13+
private IPaneSettingsService PaneSettingsService { get; } = Ioc.Default.GetService<IPaneSettingsService>();
1414

15-
private PaneContents content;
16-
private Control pane;
15+
public PanePositions Position => Panel.Content is IPane pane ? pane.Position : PanePositions.Right;
1716

1817
public PaneControl()
1918
{
2019
InitializeComponent();
2120

22-
PaneService.PropertyChanged += PaneService_PropertyChanged;
21+
PaneSettingsService.PropertyChanged += PaneService_PropertyChanged;
2322
Update();
2423
}
2524

2625
public void UpdatePosition(double panelWidth, double panelHeight)
2726
{
28-
if (pane is IPane p)
27+
if (Panel.Content is IPane pane)
2928
{
30-
p.UpdatePosition(panelWidth, panelHeight);
31-
Position = p.Position;
29+
pane.UpdatePosition(panelWidth, panelHeight);
3230
}
33-
if (pane is not null)
31+
if (Panel.Content is Control control)
3432
{
35-
MinWidth = pane.MinWidth;
36-
MaxWidth = pane.MaxWidth;
37-
MinHeight = pane.MinHeight;
38-
MaxHeight = pane.MaxHeight;
33+
MinWidth = control.MinWidth;
34+
MaxWidth = control.MaxWidth;
35+
MinHeight = control.MinHeight;
36+
MaxHeight = control.MaxHeight;
3937
}
4038
}
4139

@@ -49,17 +47,11 @@ private void PaneService_PropertyChanged(object sender, PropertyChangedEventArgs
4947

5048
private void Update()
5149
{
52-
var newContent = PaneService.Content;
50+
var newContent = PaneSettingsService.Content;
5351
if (content != newContent)
5452
{
5553
content = newContent;
56-
pane = GetPane(content);
57-
58-
Panel.Children.Clear();
59-
if (pane is not null)
60-
{
61-
Panel.Children.Add(pane);
62-
}
54+
Panel.Content = GetPane(content);
6355
}
6456
}
6557

0 commit comments

Comments
 (0)