@@ -11,13 +11,55 @@ namespace LLCOM.ViewModels;
1111
1212public 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}
0 commit comments