Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/radj307/xamltimers
WPF behavior that updates data bindings on a timer, entirely from XAML
https://github.com/radj307/xamltimers
bindings data-binding databindings dotnet dotnet- dotnet-core interval net6 netcore netcore6 timer timers update wpf wpf-behaviors xaml xaml-timers xamltimer xamltimers
Last synced: about 2 months ago
JSON representation
WPF behavior that updates data bindings on a timer, entirely from XAML
- Host: GitHub
- URL: https://github.com/radj307/xamltimers
- Owner: radj307
- License: mit
- Created: 2022-08-12T00:38:03.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-10T19:54:22.000Z (about 1 year ago)
- Last Synced: 2024-11-15T13:24:35.706Z (about 2 months ago)
- Topics: bindings, data-binding, databindings, dotnet, dotnet-, dotnet-core, interval, net6, netcore, netcore6, timer, timers, update, wpf, wpf-behaviors, xaml, xaml-timers, xamltimer, xamltimers
- Language: C#
- Homepage:
- Size: 64.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# XamlTimers
WPF behaviors that update bindings or execute a callback method on a configurable interval.
You can toggle the timers at any time; or even bind the `EnableTimer` property to another control, such as a `CheckBox`.# Usage
Requires Microsoft's WPF Behaviors NuGet package:
- `Microsoft.Xaml.Behaviors.Wpf` *([GitHub](https://github.com/Microsoft/XamlBehaviorsWpf), [NuGet](https://www.nuget.org/packages/Microsoft.Xaml.Behaviors.Wpf))*
To use the above package in XAML, add this namespace to your Window:
`http://schemas.microsoft.com/xaml/behaviors`## Namespace
### C#
```csharp
using XamlTimers;
```### XAML
```xaml
xmlns:behavior="clr-namespace:XamlTimers;assembly=XamlTimers"
```## Behaviors
*Properties that don't have default values are **required**!*
### `IntervalUpdateBinding`
#### Properties
| Property | Type | Default Value | Description |
|-----------------|------|---------|-------------|
| `EnableTimer` | `bool` | `true` | When `true`, the timer is enabled & the specified binding is updated every time the `Interval` has elapsed;
When `false`, the timer is disabled & no updates occur. |
| `Interval` | `double` | | The timer interval, in milliseconds. |
| `Property` | `DependencyProperty` | | Specifies the target property of the attached object to update the databinding on.
This should be specified in the form `"{x:Static .Property}"`, where the `` is the control that *defines* the property, **not the control that inherits it**.
*(i.e. `Slider.Value` => `RangeBase.ValueProperty`)* |
| `ThrowWhenPropertyIsNull` | `bool` | `true` | When `true`, an `ArgumentNullException` is thrown by the update method when `Property` is `null`; when `false`, no exception is thrown and the binding update silently fails. |
| `ThrowWhenPropertyIsMissing` | `bool` | `true` | When `true`, an `ArgumentNullException` is thrown by the update method when `Property` doesn't exist on the attached object; when `false`, no exception is thrown and the binding update silently fails. |### `IntervalCallback`
#### Properties
| Property | Default | Description |
|-----------------|---------|-------------|
| `EnableTimer` | `true` | When `true`, the timer is enabled & `TimerCallback` is called every time the `Interval` has elapsed;
When `false`, the timer is disabled & `TimerCallback` is not called. |
| `Interval` | | The timer interval, in milliseconds. *(type `double`)* |
| `TimerCallback` | | A callback delegate of type `System.Timers.ElapsedEventHandler` that will be invoked every time the timer is triggered. |### `BaseIntervalBehavior`
If you want to create your own timer class, you can inherit from the abstract base class with your own implementation.
See the [source code](BaseIntervalBehavior.cs) for implementation details & examples.