Skip to content

Commit 391ec00

Browse files
committed
add: 各个页面
1 parent 5c69ffa commit 391ec00

31 files changed

+495
-18
lines changed

llcomNext/LLCOM/App.axaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@
1818

1919
<Application.Resources>
2020
<FontFamily x:Key="Phosphor">/Assets/Fonts/Phosphor.ttf#Phosphor</FontFamily>
21-
<FontFamily x:Key="PhosphorFill">/Assets/Fonts/Phosphor.ttf#Phosphor-Fill</FontFamily>
2221
</Application.Resources>
2322
</Application>

llcomNext/LLCOM/App.axaml.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@ public override void OnFrameworkInitializationCompleted()
2424

2525
collection.AddSingleton<MainWindowViewModel>();
2626
collection.AddSingleton<MainViewModel>();
27+
collection.AddSingleton<DataPageViewModel>();
28+
collection.AddSingleton<ToolsPageViewModel>();
29+
collection.AddSingleton<ScriptPageViewModel>();
30+
collection.AddSingleton<OnlinePageViewModel>();
31+
collection.AddSingleton<SettingPageViewModel>();
32+
33+
collection.AddSingleton<PacketDataViewModel>();
34+
collection.AddSingleton<TerminalViewModel>();
35+
collection.AddSingleton<WaveformViewModel>();
2736

2837
//用于获取别的ViewModel
29-
collection.AddSingleton<Func<Type, ViewModelBase?>>(x => type => serviceProvider!.GetService(type) as ViewModelBase);
38+
collection.AddSingleton<Func<Type, ViewModelBase>>(x => type => (ViewModelBase)serviceProvider!.GetService(type));
3039

3140
serviceProvider = collection.BuildServiceProvider();
3241

llcomNext/LLCOM/Styles/MainStyle.axaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Design.PreviewWith>
33
<StackPanel>
44
<Button Classes="IconButton" Content="&#xEB56;" />
5-
<Button Classes="IconButtonActivated" Content="&#xEB56;" />
5+
<Button Classes="IconButtonActive" Content="&#xEB56;" />
66
</StackPanel>
77
</Design.PreviewWith>
88

@@ -16,8 +16,8 @@
1616
<Setter Property="Width" Value="40" />
1717
<Setter Property="FontSize" Value="20" />
1818
</Style>
19-
<Style Selector="Button.IconButtonActivated">
20-
<Setter Property="FontFamily" Value="{DynamicResource PhosphorFill}" />
19+
<Style Selector="Button.IconButtonActive">
20+
<Setter Property="FontFamily" Value="{DynamicResource Phosphor}" />
2121
<Setter Property="Padding" Value="0" />
2222
<Setter Property="Theme" Value="{DynamicResource SolidButton}" />
2323
<Setter Property="Height" Value="40" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using CommunityToolkit.Mvvm.ComponentModel;
3+
4+
namespace LLCOM.ViewModels;
5+
6+
public partial class DataPageViewModel: ViewModelBase
7+
{
8+
private Func<Type, ViewModelBase> _getService;
9+
10+
//用于设计时预览,正式代码中无效
11+
public DataPageViewModel() {}
12+
13+
public DataPageViewModel(Func<Type, ViewModelBase> getService)
14+
{
15+
_getService = getService;
16+
}
17+
}

llcomNext/LLCOM/ViewModels/MainViewModel.cs

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,55 @@ namespace LLCOM.ViewModels;
1111

1212
public partial class MainViewModel : ViewModelBase
1313
{
14-
private Func<Type, ViewModelBase?> GetService;
14+
private Func<Type, ViewModelBase> _getService;
1515

16-
16+
[ObservableProperty]
17+
[NotifyPropertyChangedFor(
18+
nameof(IsDataPageActive),
19+
nameof(IsToolsPageActive),
20+
nameof(IsScriptPageActive),
21+
nameof(IsOnlinePageActive),
22+
nameof(IsSettingPageActive)
23+
)]
24+
private ViewModelBase _currentPage;
25+
26+
public bool IsDataPageActive => CurrentPage is DataPageViewModel;
27+
public bool IsToolsPageActive => CurrentPage is ToolsPageViewModel;
28+
public bool IsScriptPageActive => CurrentPage is ScriptPageViewModel;
29+
public bool IsOnlinePageActive => CurrentPage is OnlinePageViewModel;
30+
public bool IsSettingPageActive => CurrentPage is SettingPageViewModel;
1731

18-
public MainViewModel(Func<Type, ViewModelBase?> getService)
32+
//用于设计时预览,正式代码中无效
33+
public MainViewModel() {}
34+
35+
public MainViewModel(Func<Type, ViewModelBase> getService)
1936
{
20-
GetService = getService;
37+
_getService = getService;
38+
CurrentPage = _getService(typeof(DataPageViewModel));
39+
CurrentDataPage = _getService(typeof(PacketDataViewModel));
2140
}
2241

42+
[RelayCommand]
43+
private void DataPageButton() => CurrentPage = _getService(typeof(DataPageViewModel));
44+
[RelayCommand]
45+
private void ToolsPageButton() => CurrentPage = _getService(typeof(ToolsPageViewModel));
46+
[RelayCommand]
47+
private void ScriptPageButton() => CurrentPage = _getService(typeof(ScriptPageViewModel));
48+
[RelayCommand]
49+
private void OnlinePageButton() => CurrentPage = _getService(typeof(OnlinePageViewModel));
50+
[RelayCommand]
51+
private void SettingPageButton() => CurrentPage = _getService(typeof(SettingPageViewModel));
52+
53+
54+
//以下代码用于切换DataPage中的子页面
55+
[ObservableProperty]
56+
private ViewModelBase _currentDataPage;
57+
58+
[RelayCommand]
59+
private void PacketDataButton() => CurrentDataPage = _getService(typeof(PacketDataViewModel));
60+
[RelayCommand]
61+
private void TerminalButton() => CurrentDataPage = _getService(typeof(TerminalViewModel));
62+
[RelayCommand]
63+
private void WaveformButton() => CurrentDataPage = _getService(typeof(WaveformViewModel));
64+
2365
}

llcomNext/LLCOM/ViewModels/MainWindowViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
namespace LLCOM.ViewModels
77
{
88

9-
public partial class MainWindowViewModel(Func<Type, ViewModelBase?> getService) : ViewModelBase
9+
public partial class MainWindowViewModel(Func<Type, ViewModelBase> getService) : ViewModelBase
1010
{
1111
[ObservableProperty]
12-
private MainViewModel _mainViewModel = (MainViewModel)getService(typeof(MainViewModel))!;
12+
private MainViewModel _mainViewModel = (MainViewModel)getService(typeof(MainViewModel));
1313
}
1414
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace LLCOM.ViewModels;
4+
5+
public partial class OnlinePageViewModel: ViewModelBase
6+
{
7+
private Func<Type, ViewModelBase> _getService;
8+
9+
//用于设计时预览,正式代码中无效
10+
public OnlinePageViewModel() {}
11+
12+
public OnlinePageViewModel(Func<Type, ViewModelBase> getService)
13+
{
14+
_getService = getService;
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace LLCOM.ViewModels;
4+
5+
public partial class PacketDataViewModel : ViewModelBase
6+
{
7+
private Func<Type, ViewModelBase> _getService;
8+
9+
//用于设计时预览,正式代码中无效
10+
public PacketDataViewModel() {}
11+
12+
public PacketDataViewModel(Func<Type, ViewModelBase> getService)
13+
{
14+
_getService = getService;
15+
}
16+
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace LLCOM.ViewModels;
4+
5+
public partial class ScriptPageViewModel : ViewModelBase
6+
{
7+
private Func<Type, ViewModelBase> _getService;
8+
9+
//用于设计时预览,正式代码中无效
10+
public ScriptPageViewModel() {}
11+
12+
public ScriptPageViewModel(Func<Type, ViewModelBase> getService)
13+
{
14+
_getService = getService;
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace LLCOM.ViewModels;
4+
5+
public partial class SettingPageViewModel : ViewModelBase
6+
{
7+
private Func<Type, ViewModelBase> _getService;
8+
9+
//用于设计时预览,正式代码中无效
10+
public SettingPageViewModel() {}
11+
12+
public SettingPageViewModel(Func<Type, ViewModelBase> getService)
13+
{
14+
_getService = getService;
15+
}
16+
}

0 commit comments

Comments
 (0)