Default Styles/ControlThemes

This commit is contained in:
ClemensFischer 2024-07-05 09:20:30 +02:00
parent 4608f9a511
commit dd7a4814af
8 changed files with 34 additions and 67 deletions

View file

@ -93,14 +93,20 @@ namespace MapControl
public static DependencyProperty AddOwner<TOwner, TValue>(
DependencyProperty property,
TValue defaultValue = default,
Action<TOwner, TValue, TValue> changed = null)
where TOwner : DependencyObject
{
FrameworkPropertyMetadata metadata = null;
var metadata = new FrameworkPropertyMetadata();
if (!Equals(defaultValue, property.GetMetadata(typeof(TOwner)).DefaultValue))
{
metadata.DefaultValue = defaultValue;
}
if (changed != null)
{
metadata = new FrameworkPropertyMetadata((o, e) => changed((TOwner)o, (TValue)e.OldValue, (TValue)e.NewValue));
metadata.PropertyChangedCallback = (o, e) => changed((TOwner)o, (TValue)e.OldValue, (TValue)e.NewValue);
}
return property.AddOwner(typeof(TOwner), metadata);

View file

@ -75,6 +75,7 @@ namespace MapControl
static MapBase()
{
BackgroundProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(Brushes.White));
ClipToBoundsProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(true));
DefaultStyleKeyProperty.OverrideMetadata(typeof(MapBase), new FrameworkPropertyMetadata(typeof(MapBase)));
}

View file

@ -14,7 +14,7 @@ namespace MapControl
DependencyPropertyHelper.AddOwner<MapItem, bool>(MapPanel.AutoCollapseProperty);
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty,
DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty, null,
(item, oldValue, newValue) => item.UpdateMapTransform(newValue));
static MapItem()

View file

@ -16,7 +16,7 @@ namespace MapControl
}
public static readonly DependencyProperty DataProperty =
DependencyPropertyHelper.AddOwner<MapPath, Geometry>(Path.DataProperty,
DependencyPropertyHelper.AddOwner<MapPath, Geometry>(Path.DataProperty, null,
(path, oldValue, newValue) => path.DataPropertyChanged(oldValue, newValue));
public Geometry Data

View file

@ -4,7 +4,6 @@
xmlns:map="clr-namespace:MapControl">
<Style TargetType="map:MapBase">
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="Black"/>
</Style>