Skip to content

Commit 4b5bf4a

Browse files
authored
Add percentage text to drive allocation indicator in properties (#5939)
1 parent 46bd1c4 commit 4b5bf4a

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

Files/ViewModels/SelectedItemsPropertiesViewModel.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public ulong DriveUsedSpaceValue
288288
{
289289
SetProperty(ref driveUsedSpaceValue, value);
290290
DriveUsedSpace = $"{ByteSize.FromBytes(DriveUsedSpaceValue).ToBinaryString().ConvertSizeAbbreviation()} ({ByteSize.FromBytes(DriveUsedSpaceValue).Bytes:#,##0} {"ItemSizeBytes".GetLocalized()})";
291-
DriveUsedSpaceDoubleValue = Convert.ToDouble(DriveUsedSpaceValue);
291+
OnPropertyChanged(nameof(DrivePercentageValue));
292292
}
293293
}
294294

@@ -421,7 +421,7 @@ public ulong DriveCapacityValue
421421
{
422422
SetProperty(ref driveCapacityValue, value);
423423
DriveCapacity = $"{ByteSize.FromBytes(DriveCapacityValue).ToBinaryString().ConvertSizeAbbreviation()} ({ByteSize.FromBytes(DriveCapacityValue).Bytes:#,##0} {"ItemSizeBytes".GetLocalized()})";
424-
DriveCapacityDoubleValue = Convert.ToDouble(DriveCapacityValue);
424+
OnPropertyChanged(nameof(DrivePercentageValue));
425425
}
426426
}
427427

@@ -445,20 +445,9 @@ public Visibility DriveCapacityVisibiity
445445
set => SetProperty(ref driveCapacityVisibiity, value);
446446
}
447447

448-
private double driveCapacityDoubleValue;
449-
450-
public double DriveCapacityDoubleValue
451-
{
452-
get => driveCapacityDoubleValue;
453-
set => SetProperty(ref driveCapacityDoubleValue, value);
454-
}
455-
456-
private double driveUsedSpaceDoubleValue;
457-
458-
public double DriveUsedSpaceDoubleValue
448+
public double DrivePercentageValue
459449
{
460-
get => driveUsedSpaceDoubleValue;
461-
set => SetProperty(ref driveUsedSpaceDoubleValue, value);
450+
get => DriveCapacityValue > 0 ? (double)DriveUsedSpaceValue / (double)DriveCapacityValue * 100 : 0;
462451
}
463452

464453
private Visibility itemAttributesVisibility = Visibility.Visible;

Files/Views/Pages/PropertiesGeneral.xaml

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
x:Class="Files.Views.PropertiesGeneral"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
56
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
67
xmlns:local="using:Files.ViewModels.Properties"
78
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
89
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
9-
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
1010
xmlns:usercontrols="using:Files.UserControls"
1111
Loaded="Properties_Loaded"
1212
mc:Ignorable="d">
@@ -341,9 +341,45 @@
341341
Height="70"
342342
Margin="10"
343343
IsIndeterminate="False"
344-
Maximum="{x:Bind ViewModel.DriveCapacityDoubleValue, Mode=OneWay}"
345344
Visibility="{x:Bind ViewModel.DriveCapacityVisibiity, Mode=OneWay}"
346-
Value="{x:Bind ViewModel.DriveUsedSpaceDoubleValue, Mode=OneWay}" />
345+
Value="{x:Bind ViewModel.DrivePercentageValue, Mode=OneWay}">
346+
347+
<muxc:ProgressRing.Template>
348+
<ControlTemplate TargetType="muxc:ProgressRing">
349+
<Grid x:Name="LayoutRoot" Background="Transparent">
350+
<Grid.Resources>
351+
<converters:StringFormatConverter x:Key="StringFormatConverter" />
352+
</Grid.Resources>
353+
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
354+
<TextBlock
355+
Margin="0"
356+
FontWeight="SemiBold"
357+
Text="{Binding Value, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource StringFormatConverter}, ConverterParameter='{}{0:0}%', Mode=OneWay}"
358+
TextAlignment="Center" />
359+
</StackPanel>
360+
361+
<!-- AnimatedVisualPlayer for Lottie -->
362+
<muxc:AnimatedVisualPlayer
363+
x:Name="LottiePlayer"
364+
AutoPlay="false"
365+
Opacity="1"
366+
Stretch="fill" />
367+
368+
<VisualStateManager.VisualStateGroups>
369+
<VisualStateGroup x:Name="CommonStates">
370+
<VisualState x:Name="Inactive">
371+
<VisualState.Setters>
372+
<Setter Target="LayoutRoot.Opacity" Value="0" />
373+
</VisualState.Setters>
374+
</VisualState>
375+
<VisualState x:Name="DeterminateActive" />
376+
<VisualState x:Name="Active" />
377+
</VisualStateGroup>
378+
</VisualStateManager.VisualStateGroups>
379+
</Grid>
380+
</ControlTemplate>
381+
</muxc:ProgressRing.Template>
382+
</muxc:ProgressRing>
347383

348384
<TextBlock
349385
x:Uid="PropertiesAttributes"

0 commit comments

Comments
 (0)