LazyApiPack.Mvvm.Wpf
0.0.5
See the version list below for details.
dotnet add package LazyApiPack.Mvvm.Wpf --version 0.0.5
NuGet\Install-Package LazyApiPack.Mvvm.Wpf -Version 0.0.5
<PackageReference Include="LazyApiPack.Mvvm.Wpf" Version="0.0.5" />
paket add LazyApiPack.Mvvm.Wpf --version 0.0.5
#r "nuget: LazyApiPack.Mvvm.Wpf, 0.0.5"
// Install LazyApiPack.Mvvm.Wpf as a Cake Addin #addin nuget:?package=LazyApiPack.Mvvm.Wpf&version=0.0.5 // Install LazyApiPack.Mvvm.Wpf as a Cake Tool #tool nuget:?package=LazyApiPack.Mvvm.Wpf&version=0.0.5
About this pack
Supports MVVM functionality for applications.
Overview
The framework is currently under development. Breaking changes may occur!
Basic functions
- View - ViewModel -Model pattern
- Services (Dependency Injection) in ViewModels and Services
- Stores
- Regions
- Modules
- Communication between modules
- Multilingual
Application scaffold
App.cs
The application derives from MvvmApplication
and needs the OnSetup
method overridden.
public partial class App : MvvmApplication
{
public App() : base()
{
}
protected override void OnSetup(MvvmApplicationConfiguration configuration)
{
configuration
.WithModule<NeuralFireworksModule>()
.WithShellWindow<MainWindow>()
.WithSplashWindow<SplashWindow>();
}
}
The application itself hosts one or more modules that implement the business logic. The application itself only provides platform specific code such as Dialog Windows, Shell Window and SplashScreen
All Windows must implement the IWindowTemplate / ISplashScreenTemplate interface.
Module.cs
public class NeuralFireworksModule : MvvmModule
{
private string _moduleId = "net.thelazycrazybrain.NeuralFireworks.Module.NeuralFireworksModule";
public override string ModuleId { get => _moduleId; }
public override void OnSetup(MvvmModuleConfiguration configuration)
{
configuration
.WithStore(new SolutionStore())
.WithModule<IronPythonModule>()
.WithViews("NeuralFireworks.Module.Views")
.WithViewModels("NeuralFireworks.Module.ViewModels")
.WithLocalizationNamespaces(typeof(NeuralFireworksModule).Assembly, new[] { "NeuralFireworks.Module.Localizations" })
.WithService<ILocalizationService, LocalizationService>()
.WithService<ILogger, FileLogger>()
.WithService<IAINetworkService, AINetworkService>(true)
.WithRegionAdapter<MultiWindowRegionAdapter>()
.WithRegionAdapter<ContentControlRegionAdapter>()
.WithRegionAdapter<TabControlRegionAdapter>()
.WithRegionAdapter<CloseableTabControlRegionAdapter>();
}
public override void OnSetupComplete()
{
MvvmApplication.Navigation.NavigateTo("InterpreterViewModel", "ModalRegion", null, null);
MvvmApplication.Navigation.NavigateTo("DebugViewModel", "Main", null, null);
}
}
The module itself configures the application.
TBD
Caption of a view
If you want to support a caption for a view (to show in a tab), use the MVVM Caption Pattern
Patterns
MVVM Caption Pattern
To get a caption of a view (for example - to show in a tab), use this pattern.
Class Layout:
public class MyView : UserControl
{
public MyView() {
DataContext = new MyViewModel();
}
public override string ToString() {
return "MyView";
}
}
public class MyViewModel : ISupportModel {
public MyViewModel() {
Model = new MyModel();
}
public string Title { get; } = "My ViewModel Title";
}
public class MyModel {
public string Caption { get; } = "My Model Title";
}
public class MyModelDataContext {
}
Call:
string caption = AppLocalizationManager.Instance.GetMvvmCaption(view);
Result:
- The result of the call and this class layout would be "My Model Title".
- If the Caption property of MyModel would not exist or would return
null
, the result would be "My ViewModel Title". - If the Title property of MyViewModel were
null
, the result would be "MyView", because the methodToString()
is overridden. - If the method
ToString()
was not overridden, the result would benull
.
Pattern:
The process goes down in the class hierarchy and then checks, if that class inherits either from ISupportModel (Property: Model) or from FrameworkElement (Property: DataContext) looks for the properties "Caption
" (Public, Not-Static), "Title
" (Public, Not-Static) and the ToString()
method (overridden!).
If the properties are not found or null
, the process goes up one step in the hierarchy and looks for that pattern there until it reaches the topmost element (view
).
Example:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net8.0-windows was computed. |
-
net6.0-windows7.0
- LazyApiPack.Collections (>= 0.1.0)
- LazyApiPack.Localization (>= 0.2.0)
- LazyApiPack.Wpf.Controls (>= 0.0.2)
- LazyApiPack.Wpf.Utils (>= 0.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Supports MVVM functionality for WPF applications.