Skip to content

Commit 4ce9ada

Browse files
committed
feat: resources management,import EnumToBooleanConverter.
1 parent 44f2c17 commit 4ce9ada

File tree

7 files changed

+34
-15
lines changed

7 files changed

+34
-15
lines changed

src/Client.Avalonia/App.axaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@
1010
<Application.Styles>
1111
<semi:SemiTheme Locale="zh-CN" />
1212
</Application.Styles>
13+
14+
<Application.Resources>
15+
<ResourceDictionary>
16+
<ResourceDictionary.MergedDictionaries>
17+
<ResourceInclude Source="avares://Client.Avalonia/Themes/Resources/_index.axaml" />
18+
<ResourceInclude Source="avares://Client.Avalonia/Themes/Controls/_index.axaml" />
19+
</ResourceDictionary.MergedDictionaries>
20+
</ResourceDictionary>
21+
</Application.Resources>
1322
</Application>
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
2+
<ResourceDictionary.MergedDictionaries>
3+
<ResourceInclude Source="avares://Client.Avalonia/Themes/Controls/ToggleSwitch.axaml" />
4+
</ResourceDictionary.MergedDictionaries>
5+
</ResourceDictionary>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
2+
<StreamGeometry x:Key="IconPlay">M 5 2.90101 C 5 2.09583 5.90303 1.62081 6.56653 2.07697 L 19.8014 11.1759 C 20.3794 11.5733 20.3794 12.4267 19.8014 12.824 L 6.56653 21.923 C 5.90303 22.3792 5 21.9041 5 21.0989 V 2.90101 Z</StreamGeometry>
3+
<StreamGeometry x:Key="IconPause">M4.5 4.75C4.5 3.23122 5.73122 2 7.25 2C8.76878 2 10 3.23122 10 4.75V19.25C10 20.7688 8.76878 22 7.25 22C5.73122 22 4.5 20.7688 4.5 19.25V4.75ZM14 4.75C14 3.23122 15.2312 2 16.75 2C18.2688 2 19.5 3.23122 19.5 4.75V19.25C19.5 20.7688 18.2688 22 16.75 22C15.2312 22 14 20.7688 14 19.25V4.75Z</StreamGeometry>
4+
<StreamGeometry x:Key="IconStop">M3 6C3 4.34315 4.34315 3 6 3H18C19.6569 3 21 4.34315 21 6V18C21 19.6569 19.6569 21 18 21H6C4.34315 21 3 19.6569 3 18V6Z</StreamGeometry>
5+
<StreamGeometry x:Key="IconRestart">M4.5 2C3.67157 2 3 2.67157 3 3.5V20.5C3 21.3284 3.67157 22 4.5 22C5.32843 22 6 21.3284 6 20.5V3.5C6 2.67157 5.32843 2 4.5 2ZM8.00083 11.2137L19.3822 2.27115C20.0384 1.75562 21.0001 2.22303 21.0001 3.05746V20.9425C21.0001 21.777 20.0384 22.2444 19.3822 21.7289L8.00083 12.7863C7.49126 12.3859 7.49126 11.6141 8.00083 11.2137Z</StreamGeometry>
6+
</ResourceDictionary>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
2+
<ResourceDictionary.MergedDictionaries>
3+
<ResourceInclude Source="avares://Client.Avalonia/Themes/Resources/Icon.axaml" />
4+
</ResourceDictionary.MergedDictionaries>
5+
</ResourceDictionary>

src/Client.Avalonia/ViewModels/MainWindowViewModel.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ public partial class MainWindowViewModel : ViewModelBase
1010
{
1111
[ObservableProperty] private DownloadStatistics _statistics;
1212

13-
[ObservableProperty]
14-
[NotifyCanExecuteChangedFor(nameof(StartCommand), nameof(StopCommand))]
15-
[NotifyPropertyChangedFor(nameof(IsDownloading), nameof(IsCompleted))]
13+
[ObservableProperty] [NotifyCanExecuteChangedFor(nameof(StartCommand), nameof(StopCommand))]
1614
private DownloadStatus _status;
1715

18-
public bool IsDownloading => Status is DownloadStatus.Downloading;
19-
public bool IsCompleted => Status is DownloadStatus.Completed;
20-
2116
private readonly DispatcherTimer _timer;
2217
private readonly Random _random;
2318

src/Client.Avalonia/Views/MainWindow.axaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:vm="using:Client.Avalonia.ViewModels"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls"
67
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
78
x:Class="Client.Avalonia.Views.MainWindow"
89
x:DataType="vm:MainWindowViewModel"
@@ -12,13 +13,7 @@
1213
Title="{Binding Statistics.Version,StringFormat='General Update {0} 版本更新'}">
1314
<Window.Resources>
1415
<ResourceDictionary>
15-
<ResourceDictionary.MergedDictionaries>
16-
<ResourceInclude Source="../Themes/ToggleSwitch.axaml" />
17-
</ResourceDictionary.MergedDictionaries>
18-
<StreamGeometry x:Key="IconPlay">M 5 2.90101 C 5 2.09583 5.90303 1.62081 6.56653 2.07697 L 19.8014 11.1759 C 20.3794 11.5733 20.3794 12.4267 19.8014 12.824 L 6.56653 21.923 C 5.90303 22.3792 5 21.9041 5 21.0989 V 2.90101 Z</StreamGeometry>
19-
<StreamGeometry x:Key="IconPause">M4.5 4.75C4.5 3.23122 5.73122 2 7.25 2C8.76878 2 10 3.23122 10 4.75V19.25C10 20.7688 8.76878 22 7.25 22C5.73122 22 4.5 20.7688 4.5 19.25V4.75ZM14 4.75C14 3.23122 15.2312 2 16.75 2C18.2688 2 19.5 3.23122 19.5 4.75V19.25C19.5 20.7688 18.2688 22 16.75 22C15.2312 22 14 20.7688 14 19.25V4.75Z</StreamGeometry>
20-
<StreamGeometry x:Key="IconStop">M3 6C3 4.34315 4.34315 3 6 3H18C19.6569 3 21 4.34315 21 6V18C21 19.6569 19.6569 21 18 21H6C4.34315 21 3 19.6569 3 18V6Z</StreamGeometry>
21-
<StreamGeometry x:Key="IconRestart">M4.5 2C3.67157 2 3 2.67157 3 3.5V20.5C3 21.3284 3.67157 22 4.5 22C5.32843 22 6 21.3284 6 20.5V3.5C6 2.67157 5.32843 2 4.5 2ZM8.00083 11.2137L19.3822 2.27115C20.0384 1.75562 21.0001 2.22303 21.0001 3.05746V20.9425C21.0001 21.777 20.0384 22.2444 19.3822 21.7289L8.00083 12.7863C7.49126 12.3859 7.49126 11.6141 8.00083 11.2137Z</StreamGeometry>
16+
<converters:EnumToBoolConverter x:Key="EnumToBooleanConverter" />
2217
</ResourceDictionary>
2318
</Window.Resources>
2419

@@ -68,7 +63,9 @@
6863
<ProgressBar
6964
Name="Bar"
7065
ShowProgressText="True"
71-
Classes.Success="{Binding IsCompleted}"
66+
Classes.Success="{Binding Status,
67+
Converter={StaticResource EnumToBooleanConverter},
68+
ConverterParameter={x:Static vm:DownloadStatus.Completed}}"
7269
Value="{Binding Statistics.ProgressPercentage}">
7370
<ProgressBar.Styles>
7471
<Style Selector="ProgressBar">
@@ -100,7 +97,9 @@
10097
<ToggleSwitch
10198
Name="StartButton"
10299
Padding="8"
103-
IsChecked="{Binding IsDownloading}"
100+
IsChecked="{Binding Status,
101+
Converter={StaticResource EnumToBooleanConverter},
102+
ConverterParameter={x:Static vm:DownloadStatus.Downloading}}"
104103
Theme="{StaticResource ButtonToggleSwitch}"
105104
Command="{Binding StartCommand}">
106105
<ToolTip.Tip>

0 commit comments

Comments
 (0)