mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 14:08:32 +00:00
Avalonia: do not coerce default property value
This commit is contained in:
parent
98847f5d86
commit
603a0a7e6f
5 changed files with 21 additions and 20 deletions
|
|
@ -19,9 +19,17 @@ namespace MapControl
|
|||
bool bindTwoWayByDefault = false)
|
||||
where TOwner : AvaloniaObject
|
||||
{
|
||||
var property = AvaloniaProperty.Register<TOwner, TValue>(name, defaultValue, false,
|
||||
bindTwoWayByDefault ? Avalonia.Data.BindingMode.TwoWay : Avalonia.Data.BindingMode.OneWay, null,
|
||||
coerce != null ? ((obj, value) => coerce((TOwner)obj, value)) : null);
|
||||
Func<AvaloniaObject, TValue, TValue> coerceFunc = null;
|
||||
|
||||
if (coerce != null)
|
||||
{
|
||||
// do not coerce default value
|
||||
coerceFunc = (obj, value) => value.Equals(defaultValue) ? value : coerce((TOwner)obj, value);
|
||||
}
|
||||
|
||||
var bindingMode = bindTwoWayByDefault ? Avalonia.Data.BindingMode.TwoWay : Avalonia.Data.BindingMode.OneWay;
|
||||
|
||||
var property = AvaloniaProperty.Register<TOwner, TValue>(name, defaultValue, false, bindingMode, null, coerceFunc);
|
||||
|
||||
if (changed != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace MapControl
|
|||
true);
|
||||
|
||||
public static readonly StyledProperty<double> MinZoomLevelProperty =
|
||||
DependencyPropertyHelper.Register<MapBase, double>(nameof(MinZoomLevel), DefaultZoomLevel,
|
||||
DependencyPropertyHelper.Register<MapBase, double>(nameof(MinZoomLevel), 1d,
|
||||
(map, oldValue, newValue) => map.MinZoomLevelPropertyChanged(newValue),
|
||||
(map, value) => map.CoerceMinZoomLevelProperty(value));
|
||||
|
||||
|
|
@ -45,13 +45,13 @@ namespace MapControl
|
|||
(map, value) => map.CoerceMaxZoomLevelProperty(value));
|
||||
|
||||
public static readonly StyledProperty<double> ZoomLevelProperty =
|
||||
DependencyPropertyHelper.Register<MapBase, double>(nameof(ZoomLevel), DefaultZoomLevel,
|
||||
DependencyPropertyHelper.Register<MapBase, double>(nameof(ZoomLevel), 1d,
|
||||
(map, oldValue, newValue) => map.ZoomLevelPropertyChanged(newValue),
|
||||
(map, value) => map.CoerceZoomLevelProperty(value),
|
||||
true);
|
||||
|
||||
public static readonly StyledProperty<double> TargetZoomLevelProperty =
|
||||
DependencyPropertyHelper.Register<MapBase, double>(nameof(TargetZoomLevel), DefaultZoomLevel,
|
||||
DependencyPropertyHelper.Register<MapBase, double>(nameof(TargetZoomLevel), 1d,
|
||||
async (map, oldValue, newValue) => await map.TargetZoomLevelPropertyChanged(newValue),
|
||||
(map, value) => map.CoerceZoomLevelProperty(value),
|
||||
true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue