Skip to content

Commit

Permalink
prepare for 2.0.0 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverMorewd committed Nov 10, 2024
1 parent fa79db1 commit b284e00
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 37 deletions.
69 changes: 34 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,25 @@ namespace Lemon.ModuleNavigation.Sample.ModuleAs

/// <summary>
/// Specifies whether this module needs to be loaded on demand
/// 指定该模块是否按需加载
/// Default value is True
/// </summary>
public override bool LoadOnDemand => false;

/// <summary>
/// Alias of module for displaying usually
/// 模块的别名,一般用于显示
/// Default value is class name of Module
/// </summary>
public override string? Alias => base.Alias;

/// <summary>
/// Specifies whether this module allow multiple instances
/// If true,every navigation to this module will generate a new instance.
/// 指定该模块是否支持多实例,如果设置为true,那每次导航到该模块都会创建新的实例。
/// Default value is false.
/// </summary>
public override bool AllowMultiple => base.AllowMultiple;
public override bool ForceNew => base.ForceNew;

/// <summary>
/// Specifies whether this module can be unloaded.
/// 指定该模块是否支持卸载
/// Default value is false.
/// </summary>
public override bool CanUnload => base.CanUnload;
Expand Down Expand Up @@ -110,11 +106,6 @@ public partial class ViewA : UserControl, IView
{
InitializeComponent();
}

public void SetDataContext(IViewModel viewModel)
{
DataContext = viewModel;
}
}
```
##### ViewModel.cs
Expand All @@ -137,45 +128,53 @@ namespace Lemon.ModuleNavigation.Sample.ModuleAs
```

#### In MainView.axaml or MainWindow.axaml
##### NContainer
NContainer is an implementation with ContentControl for displaying View of Module.
##### ContentControl
```xaml
<lm:NContainer xmlns:lm="https://github.com/NeverMorewd/Lemon.ModuleNavigation" Grid.Column="1" NavigationContext="{Binding NavigationContext}" />
<ContentControl lm:NavigationExtension.ModuleContainerName="NContentControl" xmlns:lm="https://github.com/NeverMorewd/Lemon.ModuleNavigation" Grid.Column="1" />
```
##### NTabContainer
NTabContainer is an implementation with TabControl for displaying View of Module.
##### TabControl
```xaml
<lm:NTabContainer xmlns:lm="https://github.com/NeverMorewd/Lemon.ModuleNavigation" Grid.Column="1" NavigationContext="{Binding NavigationContext}" >
<lm:NTabContainer.ItemTemplate>
<TabControl lm:NavigationExtension.ModuleContainerName="NTabControl" xmlns:lm="https://github.com/NeverMorewd/Lemon.ModuleNavigation" Grid.Column="1" >
<TabControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Spacing="2">
<TextBlock Text="{Binding Alias}" />
<!-- Adding lm:NTabContainerBehaviors.CanUnload to a Button to make this moule can be unloaded with click event. -->
<Button lm:NTabContainerBehaviors.CanUnload="{Binding CanUnload}"/>
<!-- Adding TabControlBehaviors.CanUnload to a Button to make this moule can be unloaded with click event. -->
<Button lm:NavigationExtension.CanUnload="{Binding CanUnload}"/>
</StackPanel>
</DataTemplate>
</lm:NTabContainer.ItemTemplate>
<lm:NTabContainer.ContentTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl Content="{Binding View}" />
</DataTemplate>
</lm:NTabContainer.ContentTemplate>
</TabControl.ContentTemplate>
</NTabContainer>
```
#### MainViewModel.cs
```csharp
public class MainViewModel : ViewModelBase, INavigationContextProvider
public class MainViewModel : ViewModelBase, IServiceAware
{
public readonly NavigationService _navigationService;
public MainViewModel(NavigationContext navigationContext,
IEnumerable<IModule> modules,
NavigationService navigationService)
private readonly NavigationService _navigationService;
private readonly IServiceProvider _serviceProvider;
private readonly IDialogService _dialogService;
private readonly ILogger _logger;
public MainViewModel(IEnumerable<IModule> modules,
IServiceProvider serviceProvider,
NavigationService navigationService,
IDialogService dialogService,
ILogger<MainViewModel> logger)
{
_logger = logger;
_navigationService = navigationService;
NavigationContext = navigationContext;
_serviceProvider = serviceProvider;
_dialogService = dialogService;
Modules = new ObservableCollection<IModule>(modules);
}

/// <summary>
/// IServiceAware
/// <summary>
public IServiceProvider ServiceProvider => _serviceProvider;
/// <summary>
/// Navigation is triggered based on the timing of the customization
/// </summary>
Expand All @@ -191,11 +190,6 @@ public class MainViewModel : ViewModelBase, INavigationContextProvider
get;
set;
}

public NavigationContext NavigationContext
{
get;
}
}

```
Expand All @@ -213,9 +207,14 @@ class Program
var hostBuilder = Host.CreateApplicationBuilder();

// module navigation
hostBuilder.Services.AddNavigationContext();
hostBuilder.Services.AddAvaNavigationSupport();
// modules
hostBuilder.Services.AddModule<ModuleA>();
hostBuilder.Services.AddModule<ModuleB>();
hostBuilder.Services.AddModule<ModuleC>();
// views
hostBuilder.Services.AddView<ViewAlpha, ViewAlphaViewModel>(nameof(ViewAlpha));
hostBuilder.Services.AddView<ViewBeta, ViewBetaViewModel>(nameof(ViewAlpha));

hostBuilder.Services.AddAvaloniauiDesktopApplication<App>(BuildAvaloniaApp);
hostBuilder.Services.AddMainWindow<MainWindow, MainViewModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Title>Lemon.ModuleNavigation.Avaloniaui</Title>
<Description>Extending Lemon.ModuleNavigation, this package provides NavigationContainers specifically designed for AvaloniaUI.</Description>
<PackageIcon>lemon-100.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -25,6 +26,10 @@
</ItemGroup>

<ItemGroup>
<None Include="..\..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="lemon-100.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void Main(string[] args)
hostBuilder.Services.AddModule<ModuleC>();
// views
hostBuilder.Services.AddView<ViewAlpha, ViewAlphaViewModel>(nameof(ViewAlpha));
hostBuilder.Services.AddView<ViewBeta, ViewBetaViewModel>(nameof(ViewAlpha));
hostBuilder.Services.AddView<ViewBeta, ViewBetaViewModel>(nameof(ViewBeta));

hostBuilder.Services.AddAvaloniauiDesktopApplication<App>(BuildAvaloniaApp);
hostBuilder.Services.AddMainWindow<MainWindow, MainViewModel>();
Expand Down
5 changes: 5 additions & 0 deletions src/Lemon.ModuleNavigation/Lemon.ModuleNavigation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Title>Lemon.ModuleNavigation</Title>
<PackageIcon>lemon-100.png</PackageIcon>
<Description>A lightweight module navigation framework built on top of the Microsoft Dependency Injection (MSDI) for AvaloniaUI,WPF and Xaml-platform else. Support nativeAot</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -21,6 +22,10 @@
</ItemGroup>

<ItemGroup>
<None Include="..\..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="lemon-100.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
Expand Down
2 changes: 1 addition & 1 deletion src/Package.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>1.0.1</Version>
<Version>2.0.0-beta</Version>
<Authors>Easley</Authors>
<RepositoryUrl>https://github.com/NeverMorewd/Lemon.ModuleNavigation</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down

0 comments on commit b284e00

Please sign in to comment.