Skip to content

Code Quality: Minor optimizations to XAML #10964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1533,12 +1533,6 @@
<data name="ElevateConfirmDialog.Content" xml:space="preserve">
<value>Would you like to continue as administrator?</value>
</data>
<data name="FullTrustStatusTeachingTip.Subtitle" xml:space="preserve">
<value>Files is running as administrator</value>
</data>
<data name="FullTrustStatusTeachingTip.Title" xml:space="preserve">
<value>Administrator</value>
</data>
<data name="ColumnsShortcutTooltip" xml:space="preserve">
<value>Columns (Ctrl+Shift+6)</value>
</data>
Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/UserControls/DataGridHeader.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
x:Class="Files.App.UserControls.DataGridHeader"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ciao="using:CommunityToolkit.WinUI.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Files.App.UserControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400"
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/UserControls/FilePreviews/CodePreview.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
mc:Ignorable="d">
<Border>
<ScrollViewer
Grid.Row="0"
HorizontalScrollBarVisibility="Auto"
HorizontalScrollMode="Auto">
<RichTextBlock
Expand Down
6 changes: 2 additions & 4 deletions src/Files.App/UserControls/SidebarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
xmlns:navigationcontrolitems="using:Files.App.DataModels.NavigationControlItems"
xmlns:vc="using:Files.App.ValueConverters"
HorizontalAlignment="Stretch"
d:DesignHeight="768"
d:DesignWidth="200"
Collapsed="NavigationView_Collapsed"
DisplayModeChanged="SidebarControl_DisplayModeChanged"
Expanding="NavigationView_Expanding"
Expand Down Expand Up @@ -373,7 +371,7 @@
</Grid>

<!-- This allows the user to resize the Sidebar -->
<Grid
<Border
x:Name="ResizeElementBorder"
Grid.Row="0"
Grid.RowSpan="2"
Expand All @@ -399,7 +397,7 @@
IsTabStop="True"
KeyDown="Border_KeyDown"
UseSystemFocusVisuals="True" />
</Grid>
</Border>

<!-- This is a special spot just for tabs so that the title bar DragArea can function properly -->
<Border
Expand Down
16 changes: 8 additions & 8 deletions src/Files.App/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -986,17 +986,17 @@ private void Border_PointerExited(object sender, PointerRoutedEventArgs e)
if (dragging)
return; // keep showing pressed event if currently resizing the sidebar

((Grid)sender).ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Arrow));
VisualStateManager.GoToState(((Grid)sender).FindAscendant<SplitView>(), "ResizerNormal", true);
((Border)sender).ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Arrow));
VisualStateManager.GoToState(((Border)sender).FindAscendant<SplitView>(), "ResizerNormal", true);
}

private void Border_PointerEntered(object sender, PointerRoutedEventArgs e)
{
if (DisplayMode != NavigationViewDisplayMode.Expanded)
return;

((Grid)sender).ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.SizeWestEast));
VisualStateManager.GoToState(((Grid)sender).FindAscendant<SplitView>(), "ResizerPointerOver", true);
((Border)sender).ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.SizeWestEast));
VisualStateManager.GoToState(((Border)sender).FindAscendant<SplitView>(), "ResizerPointerOver", true);
}

private void SetSize(double val, bool closeImmediatleyOnOversize = false)
Expand Down Expand Up @@ -1024,8 +1024,8 @@ private void SetSize(double val, bool closeImmediatleyOnOversize = false)

private void ResizeElementBorder_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
((Grid)sender).ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Arrow));
VisualStateManager.GoToState(((Grid)sender).FindAscendant<SplitView>(), "ResizerNormal", true);
((Border)sender).ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Arrow));
VisualStateManager.GoToState(((Border)sender).FindAscendant<SplitView>(), "ResizerNormal", true);
UserSettingsService.AppearanceSettingsService.SidebarWidth = OpenPaneLength;
dragging = false;
}
Expand All @@ -1041,8 +1041,8 @@ private void ResizeElementBorder_ManipulationStarted(object sender, Manipulation
return;

originalSize = IsPaneOpen ? UserSettingsService.AppearanceSettingsService.SidebarWidth : CompactPaneLength;
((Grid)sender).ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.SizeWestEast));
VisualStateManager.GoToState(((Grid)sender).FindAscendant<SplitView>(), "ResizerPressed", true);
((Border)sender).ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.SizeWestEast));
VisualStateManager.GoToState(((Border)sender).FindAscendant<SplitView>(), "ResizerPressed", true);
dragging = true;
}

Expand Down
64 changes: 8 additions & 56 deletions src/Files.App/UserControls/StatusBarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,38 @@
x:Class="Files.App.UserControls.StatusBarControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters1="using:CommunityToolkit.WinUI.UI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Files.App.Helpers"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="40"
d:DesignHeight="32"
d:DesignWidth="400"
mc:Ignorable="d">
<UserControl.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="ButtonBorderBrushDisabled" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBackgroundDisabled" Color="Transparent" />

<Style
x:Key="StatusBarButtonStyle"
BasedOn="{StaticResource DefaultButtonStyle}"
TargetType="Button">
<Setter Property="Padding" Value="0" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Width" Value="32" />
<Setter Property="Height" Value="32" />
</Style>
</ResourceDictionary>
</UserControl.Resources>

<Grid
<StackPanel
Height="32"
Padding="8,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
VerticalAlignment="Stretch"
Orientation="Horizontal"
Spacing="8">

<TextBlock
x:Name="DirectoryItemCount"
Grid.Column="0"
Margin="0,0,12,0"
VerticalAlignment="Center"
x:Load="{x:Bind ShowInfoText, Mode=OneWay}"
Text="{x:Bind DirectoryPropertiesViewModel.DirectoryItemCount, Mode=OneWay}" />

<TextBlock
x:Name="SelectedItemsCountString"
Grid.Column="1"
Margin="0,0,12,0"
VerticalAlignment="Center"
x:Load="{x:Bind ShowInfoText, Mode=OneWay}"
Text="{x:Bind SelectedItemsPropertiesViewModel.SelectedItemsCountString, Mode=OneWay}"
Visibility="{x:Bind SelectedItemsPropertiesViewModel.IsItemSelected, Mode=OneWay}" />

<TextBlock
x:Name="ItemSize"
Grid.Column="2"
Margin="0,0,12,0"
VerticalAlignment="Center"
x:Load="{x:Bind ShowInfoText, Mode=OneWay}"
Text="{x:Bind SelectedItemsPropertiesViewModel.ItemSize, Mode=OneWay}"
Visibility="{x:Bind SelectedItemsPropertiesViewModel.ItemSizeVisibility, Mode=OneWay}" />

<Button
x:Name="FullTrustStatus"
Grid.Column="4"
VerticalAlignment="Center"
x:Load="{x:Bind AppModel.IsAppElevated, Mode=OneWay}"
AccessKey="M"
Click="FullTrustStatus_Click"
FontSize="16"
Style="{StaticResource StatusBarButtonStyle}">
<FontIcon FontSize="14" Glyph="&#xEA18;" />
</Button>

<TeachingTip
x:Name="FullTrustStatusTeachingTip"
Title="{helpers:ResourceString Name=FullTrustStatusTeachingTip/Title}"
Grid.ColumnSpan="5"
Subtitle="{helpers:ResourceString Name=FullTrustStatusTeachingTip/Subtitle}"
Target="{x:Bind FullTrustStatus}"
Visibility="Collapsed" />
</Grid>
</StackPanel>
</UserControl>
7 changes: 0 additions & 7 deletions src/Files.App/UserControls/StatusBarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace Files.App.UserControls
{
public sealed partial class StatusBarControl : UserControl, INotifyPropertyChanged
{
public AppModel AppModel => App.AppModel;

public DirectoryPropertiesViewModel DirectoryPropertiesViewModel
{
get => (DirectoryPropertiesViewModel)GetValue(DirectoryPropertiesViewModelProperty);
Expand Down Expand Up @@ -45,11 +43,6 @@ public StatusBarControl()
this.InitializeComponent();
}

private void FullTrustStatus_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
FullTrustStatusTeachingTip.IsOpen = true;
}

public event PropertyChangedEventHandler PropertyChanged;

private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
x:Class="Files.App.Views.LayoutModes.DetailsLayoutBrowser"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:animations="using:CommunityToolkit.WinUI.UI.Animations"
xmlns:behaviors="using:CommunityToolkit.WinUI.UI.Behaviors"
xmlns:behaviors2="using:Files.App.Behaviors"
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters"
Expand Down