Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dingpingzhang/wpfextensions
Some syntactic sugar for Wpf development.
https://github.com/dingpingzhang/wpfextensions
binding computed-property markup-extension mvvm reactive reactivity wpf xaml
Last synced: 10 days ago
JSON representation
Some syntactic sugar for Wpf development.
- Host: GitHub
- URL: https://github.com/dingpingzhang/wpfextensions
- Owner: DingpingZhang
- License: mit
- Created: 2019-01-19T08:58:20.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-09-16T02:14:33.000Z (about 1 year ago)
- Last Synced: 2024-10-11T14:29:41.351Z (25 days ago)
- Topics: binding, computed-property, markup-extension, mvvm, reactive, reactivity, wpf, xaml
- Language: C#
- Homepage:
- Size: 1.25 MB
- Stars: 247
- Watchers: 8
- Forks: 25
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WpfExtensions
English | [中文](./README.zh-CN.md)
This project comes from some scattered works I did while working on Wpf development, and is a supplement to existing Mvvm frameworks. They don't solve any major problems, they just provide some syntactic sugar and let people write a few lines of code less. Its services are not limited to Wpf development, other similar Xaml frameworks, such as Uwp, Maui, etc. should also be able to use, but I has never tested on other frameworks.
The project is structured as follows:
- `WpfExtensions.Xaml`:A number of `MarkupExtension`s are provided to simplify Xaml development.
- `WpfExtensions.Binding`:To simplify the code for property dependency updates, a function similar to the one in Vue.js for computed-property is provided.
- `WpfExtensions.Infrastructure`:Some scattered features, when the time is ripe, will be separated out and released as separate modules.## NuGet
| Package | NuGet |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `WpfExtensions.Xaml` | [![version](https://img.shields.io/nuget/v/WpfExtensions.Xaml.svg)](https://www.nuget.org/packages/WpfExtensions.Xaml) |
| `WpfExtensions.Binding` | [![version](https://img.shields.io/nuget/v/WpfExtensions.Binding.svg)](https://www.nuget.org/packages/WpfExtensions.Binding) |## 1. WpfExtensions.Binding
Brings some of the functionality of the Reactivity module from [Vue3](https://vuejs.org/api/) into Wpf.
> The term "observable" as used in the following documentation refers to objects that implement `INotifyPropertyChanged` or `INotifyCollectionChanged`.
### 1.1 `Watch`
Subscribe to an observable expression and trigger a callback function when its value changes.
```csharp
// See the source code for more overloads, whose signatures are consistent with vue3's `watch()`, and the vue3 documentation for examples.
Reactivity.Default.Watch(() => Width * Height, area => Debug.WriteLine(area));
```### 1.2 `WatchDeep`
Deep traversal subscribes to an observable object and triggers a callback function when its properties, or the properties of its properties, change.
```csharp
// `path` will print out the path to the specific property that was changed.
Reactivity.Default.WatchDeep(obj, path => Debug.WriteLine(path))
```### 1.3 `Computed`
Computed property that is an instance method of the `BindableBase` base class.
```csharp
public class ViewModel : BindableBase {
// Can be bound to xaml to automatically notify Area changes when Width or Height changes.
public double Area => Computed(() => Width * Height);
}
```## 2. WpfExtensions.Xaml
## 0. **\*New** `CommandExtension`
- View (XAML):
```xml
```
- View Model (\*.cs):
```csharp
class ViewModel
{
public void Execute() {}public void ExecuteWithArgument(string arg) {}
// The `Execute` method supports async, and its default `Can Execute` method will disable the command when it is busy.
public Task ExecuteAsync() => Task.Completed;
public Task ExecuteWithArgumentAsync(string arg) => Task.Completed;
// The `Can Execute` method does not support async.
public bool CanExecute() => true;
public bool CanExecuteWithArgument(string arg) => true;
}
```## 1. `ComposeExtension`
Combine multiple Converters into one pipeline.
```xml
```
## 2. `IfExtension`
Using the `Conditional expression` in XAML.
```xml
```
```xml
```
## 3. `SwitchExtension`
Using the `Switch expression` in XAML.
```xml
```
```xml
```
## 4. `I18nExtension`
Dynamically switch the culture resource without restarting the app.
```xml
```
## 5. `StylesExtension` (In Progress)
```xml
```