File tree Expand file tree Collapse file tree 2 files changed +31
-9
lines changed
Expand file tree Collapse file tree 2 files changed +31
-9
lines changed Original file line number Diff line number Diff line change 11using System ;
2+ using System . Collections . ObjectModel ;
23using CommunityToolkit . Mvvm . ComponentModel ;
34
45namespace LLCOM . ViewModels ;
@@ -7,11 +8,26 @@ public partial class DataPageViewModel: ViewModelBase
78{
89 private Func < Type , ViewModelBase > _getService ;
910
11+ [ ObservableProperty ]
12+ private int _selectedTabIndex = 0 ;
13+
14+ [ ObservableProperty ]
15+ private ObservableCollection < DataPageTabItemModel > _tabList = new ( ) ;
16+
1017 //用于设计时预览,正式代码中无效
1118 public DataPageViewModel ( ) { }
1219
1320 public DataPageViewModel ( Func < Type , ViewModelBase > getService )
1421 {
1522 _getService = getService ;
23+
24+ _tabList . Add ( new DataPageTabItemModel ( "test1" , _getService ( typeof ( LogPageViewModel ) ) ) ) ;
25+ _tabList . Add ( new DataPageTabItemModel ( "test2" , _getService ( typeof ( OnlinePageViewModel ) ) ) ) ;
1626 }
27+ }
28+
29+ public class DataPageTabItemModel ( string header , ViewModelBase content )
30+ {
31+ public string Header { get ; } = header ;
32+ public ViewModelBase Content { get ; } = content ;
1733}
Original file line number Diff line number Diff line change 11<UserControl
2- d : DesignHeight =" 800"
3- d : DesignWidth =" 381"
4- mc : Ignorable =" d"
52 x : Class =" LLCOM.Views.DataPageView"
6- x : DataType =" vm:DataPageViewModel"
73 xmlns =" https://github.com/avaloniaui"
4+ xmlns : x =" http://schemas.microsoft.com/winfx/2006/xaml"
85 xmlns : d =" http://schemas.microsoft.com/expression/blend/2008"
96 xmlns : mc =" http://schemas.openxmlformats.org/markup-compatibility/2006"
107 xmlns : vm =" using:LLCOM.ViewModels"
11- xmlns : x =" http://schemas.microsoft.com/winfx/2006/xaml" >
8+ d : DesignHeight =" 800"
9+ d : DesignWidth =" 381"
10+ x : DataType =" vm:DataPageViewModel"
11+ mc : Ignorable =" d" >
1212 <Design .DataContext>
1313 <vm : DataPageViewModel />
1414 </Design .DataContext>
15- <StackPanel >
16- <TextBlock Text =" DataPageView" />
17- <ToggleSwitch />
18- </StackPanel >
15+ <TabControl
16+ DisplayMemberBinding =" {Binding Header, x:DataType=vm:DataPageTabItemModel}"
17+ ItemsSource =" {Binding TabList}"
18+ SelectedIndex =" {Binding SelectedTabIndex}" >
19+ <TabControl .ContentTemplate>
20+ <DataTemplate x : DataType =" vm:DataPageTabItemModel" >
21+ <UserControl Content =" {Binding Content}" />
22+ </DataTemplate >
23+ </TabControl .ContentTemplate>
24+ </TabControl >
1925</UserControl >
You can’t perform that action at this time.
0 commit comments