WinUIStateBasedViewModel 1.0.4
dotnet add package WinUIStateBasedViewModel --version 1.0.4
NuGet\Install-Package WinUIStateBasedViewModel -Version 1.0.4
<PackageReference Include="WinUIStateBasedViewModel" Version="1.0.4" />
paket add WinUIStateBasedViewModel --version 1.0.4
#r "nuget: WinUIStateBasedViewModel, 1.0.4"
// Install WinUIStateBasedViewModel as a Cake Addin #addin nuget:?package=WinUIStateBasedViewModel&version=1.0.4 // Install WinUIStateBasedViewModel as a Cake Tool #tool nuget:?package=WinUIStateBasedViewModel&version=1.0.4
WinUI 3 Event-State Based ViewModel
This library simplifies the use of ViewModels in WinUI 3 projects, providing easy access to state flows and event handling.
Features
- State Management: Manage state immutably using state flows.
- Event Handling: Handle events effectively with a clear structure.
- Simplified ViewModel: Provides a structured approach to ViewModel implementation in WinUI 3.
Installation
To install the library, add the following NuGet package to your project:
dotnet add package WinUIStateBasedViewModel
Usage
Define Your State
Create a class that extends ViewModelState and define the properties of your state.
using WinUIViewModel.Presentation.State;
public class TestState : ViewModelState
{
public string Name { get; set; }
public string Age { get; set; }
public TestState(string name = null, string age = null)
{
Name = name;
Age = age;
}
}
Implement Your ViewModel
Create a ViewModel class that extends ViewModel<State, Event, Effect>. Implement the required methods and handle state updates and effects.
using WinUIViewModel.Presentation;
using WinUIViewModel.Presentation.State;
public class MyViewModel : ViewModel<TestState, MyEvent, MyEffect>
{
public override TestState createInitialState()
{
return new TestState { Name = "DefaultName", Age = "DefaultAge" };
}
public override void handleEffect(MyEffect effect)
{
// Handle effect
}
public void UpdateAge(string newAge)
{
var newState = currentState.Copy(newValues =>
{
newValues.Age = newAge;
});
updateState(newState);
}
}
Handling State and Events
Use the updateState method to update the state immutably. The sendEvent method can be used to handle events.
public void SomeMethod()
{
// Update the age property of the state
var newState = currentState.Copy(newValues =>
{
newValues.Age = "21";
});
updateState(newState);
}
Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-windows10.0.17763 is compatible. net7.0-windows was computed. net8.0-windows was computed. |
-
net6.0-windows10.0.17763
- Microsoft.NET.Test.Sdk (>= 17.6.2)
- Microsoft.Windows.SDK.BuildTools (>= 10.0.22621.756)
- Microsoft.WindowsAppSDK (>= 1.5.240311000)
- MSTest.TestAdapter (>= 3.4.3)
- MSTest.TestFramework (>= 3.4.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.