45 changed files with 443 additions and 159 deletions
@ -1,11 +1,18 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.ReactiveUI; |
|||
using Avalonia.Markup.Xaml; |
|||
using MyAvaloniaApp.ViewModels.Pages; |
|||
|
|||
namespace MyAvaloniaApp.Views.Pages; |
|||
|
|||
public partial class DashboardPageView : UserControl |
|||
public partial class DashboardPageView : ReactiveUserControl<DashboardPageViewModel> |
|||
{ |
|||
public DashboardPageView() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
|
|||
@ -1,12 +1,19 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.ReactiveUI; |
|||
using Avalonia.Markup.Xaml; |
|||
using MyAvaloniaApp.ViewModels.Pages; |
|||
|
|||
namespace MyAvaloniaApp.Views.Pages; |
|||
|
|||
public partial class DialogHostPageView : UserControl |
|||
public partial class DialogHostPageView : ReactiveUserControl<DialogHostPageViewModel> |
|||
{ |
|||
public DialogHostPageView() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
|
|||
|
|||
@ -1,11 +1,18 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.ReactiveUI; |
|||
using Avalonia.Markup.Xaml; |
|||
using MyAvaloniaApp.ViewModels.Pages; |
|||
|
|||
namespace MyAvaloniaApp.Views.Pages; |
|||
|
|||
public partial class HelpPageView : UserControl |
|||
public partial class HelpPageView : ReactiveUserControl<HelpPageViewModel> |
|||
{ |
|||
public HelpPageView() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
|
|||
@ -1,11 +1,18 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.ReactiveUI; |
|||
using Avalonia.Markup.Xaml; |
|||
using MyAvaloniaApp.ViewModels.Pages; |
|||
|
|||
namespace MyAvaloniaApp.Views.Pages; |
|||
|
|||
public partial class ReportsPageView : UserControl |
|||
public partial class ReportsPageView : ReactiveUserControl<ReportsPageViewModel> |
|||
{ |
|||
public ReportsPageView() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
|
|||
@ -1,11 +1,18 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.ReactiveUI; |
|||
using Avalonia.Markup.Xaml; |
|||
using MyAvaloniaApp.ViewModels.Pages; |
|||
|
|||
namespace MyAvaloniaApp.Views.Pages; |
|||
|
|||
public partial class SettingsPageView : UserControl |
|||
public partial class SettingsPageView : ReactiveUserControl<SettingsPageViewModel> |
|||
{ |
|||
public SettingsPageView() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
|
|||
@ -1,11 +1,18 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.ReactiveUI; |
|||
using Avalonia.Markup.Xaml; |
|||
using MyAvaloniaApp.ViewModels.Pages; |
|||
|
|||
namespace MyAvaloniaApp.Views.Pages; |
|||
|
|||
public partial class UsersPageView : UserControl |
|||
public partial class UsersPageView : ReactiveUserControl<UsersPageViewModel> |
|||
{ |
|||
public UsersPageView() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,68 @@ |
|||
using ReactiveUI; |
|||
using System; |
|||
using System.Diagnostics; |
|||
using System.Linq; |
|||
|
|||
namespace MyAvaloniaApp.Views; |
|||
|
|||
/// <summary>
|
|||
/// 视图定位器,用于将 ViewModel 映射到对应的 View
|
|||
/// </summary>
|
|||
public class ViewLocator : IViewLocator |
|||
{ |
|||
/// <summary>
|
|||
/// 根据 ViewModel 类型解析对应的 View
|
|||
/// </summary>
|
|||
public IViewFor? ResolveView<T>(T? viewModel, string? contract = null) |
|||
{ |
|||
if (viewModel == null) |
|||
{ |
|||
Debug.WriteLine("[ViewLocator] ViewModel is null"); |
|||
return null; |
|||
} |
|||
|
|||
var viewModelType = viewModel.GetType(); |
|||
Debug.WriteLine($"[ViewLocator] Resolving View for ViewModel: {viewModelType.FullName}"); |
|||
|
|||
// 将 ViewModel 名称转换为 View 名称
|
|||
var viewModelName = viewModelType.Name; // 只获取类名
|
|||
|
|||
// 处理多种命名模式
|
|||
var viewName = viewModelName |
|||
.Replace("PageViewModel", "PageView") |
|||
.Replace("ViewModel", "View"); |
|||
|
|||
Debug.WriteLine($"[ViewLocator] Looking for View: {viewName}"); |
|||
Debug.WriteLine($"[ViewLocator] ViewModel Namespace: {viewModelType.Namespace}"); |
|||
|
|||
// 获取与 ViewModel 在同一命名空间下的 View
|
|||
var assembly = viewModelType.Assembly; |
|||
var targetNamespace = viewModelType.Namespace?.Replace(".ViewModels", ".Views"); |
|||
Debug.WriteLine($"[ViewLocator] Target namespace: {targetNamespace}"); |
|||
|
|||
var viewType = assembly.GetTypes() |
|||
.FirstOrDefault(t => t.Name == viewName && t.Namespace == targetNamespace); |
|||
|
|||
if (viewType == null) |
|||
{ |
|||
Debug.WriteLine($"[ViewLocator] View not found: {viewName} in {targetNamespace}"); |
|||
return null; |
|||
} |
|||
|
|||
Debug.WriteLine($"[ViewLocator] Found View: {viewType.FullName}"); |
|||
|
|||
var view = Activator.CreateInstance(viewType) as IViewFor; |
|||
|
|||
if (view == null) |
|||
{ |
|||
Debug.WriteLine("[ViewLocator] Failed to create View instance"); |
|||
} |
|||
else |
|||
{ |
|||
Debug.WriteLine($"[ViewLocator] Successfully created View: {view.GetType().FullName}"); |
|||
} |
|||
|
|||
return view; |
|||
} |
|||
} |
|||
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@ |
|||
a9f27ce4bdac4bf5ca954160904d645cef7a4bde57bc6b530b0206ad45cc8eb7 |
|||
13ddcbc13e64d6798e8fba3e7da8f73f1d8b4a67a0cb18cbd7472bbf3213f169 |
|||
|
|||
Binary file not shown.
@ -1 +1 @@ |
|||
f1734234089d69d76b866b0af754acd7ebdd6538242ae0e2515f28c7d86d79fc |
|||
2e4e500ba7ddc7bd51e31ae31185388c392dd1b35d1e3220ad0285d08bdb3e15 |
|||
|
|||
@ -1 +1 @@ |
|||
0a16b036936ce872dfa8c92ae7b744f3a9f7b6c585a95920415d36320484cece |
|||
4f19c6d987d7d083abf5effe7ae4b7a817f080aaf88ae19b49d56bb536cf1927 |
|||
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@ |
|||
6db7f7d923d8c1cf44898db58528f845b13ca249bde1bdd63f24b6583b2fb618 |
|||
565664ee8d2e0eef575fae90c378130acfddf78d1f4c6886333b565cd40d783e |
|||
|
|||
Binary file not shown.
@ -1 +1 @@ |
|||
3ff08d4c1a2a8d89d5383dc9190935873755fc8f8e541fbc6f37c55291a0c028 |
|||
8df7f0f8ce54bd535a9dcb9951bcb413cbed307269589f8803381a647c43aa9d |
|||
|
|||
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue