PushpinBorder for all platforms

This commit is contained in:
Clemens 2022-02-05 15:52:17 +01:00
parent 4a38e1e1e9
commit a4f19a5976
16 changed files with 291 additions and 164 deletions

View file

@ -26,8 +26,18 @@
<Compile Include="..\Shared\*.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="PushpinBorder.xaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22000.196" />
</ItemGroup>
<ItemGroup>
<Page Update="PushpinBorder.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>

View file

@ -0,0 +1,93 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.Foundation;
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Markup;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Shapes;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
#endif
namespace MapControl
{
[ContentProperty(Name = "Child")]
public partial class PushpinBorder : UserControl
{
public static readonly DependencyProperty ArrowSizeProperty = DependencyProperty.Register(
nameof(ArrowSize), typeof(Size), typeof(PushpinBorder),
new PropertyMetadata(new Size(10d, 20d), (o, e) => ((PushpinBorder)o).SetBorderMargin()));
public static readonly DependencyProperty BorderWidthProperty = DependencyProperty.Register(
nameof(BorderWidth), typeof(double), typeof(PushpinBorder),
new PropertyMetadata(0d, (o, e) => ((PushpinBorder)o).SetBorderMargin()));
private readonly Border border = new Border();
public PushpinBorder()
{
var path = new Path
{
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
Stretch = Stretch.None
};
path.SetBinding(Shape.FillProperty, new Binding
{
Path = new PropertyPath("Background"),
Source = this
});
path.SetBinding(Shape.StrokeProperty, new Binding
{
Path = new PropertyPath("BorderBrush"),
Source = this
});
path.SetBinding(Shape.StrokeThicknessProperty, new Binding
{
Path = new PropertyPath("BorderThickness"),
Source = this
});
border.SetBinding(PaddingProperty, new Binding
{
Path = new PropertyPath("Padding"),
Source = this
});
SetBorderMargin();
var grid = new Grid();
grid.Children.Add(path);
grid.Children.Add(border);
Content = grid;
SizeChanged += (s, e) => path.Data = BuildGeometry();
}
public UIElement Child
{
get { return border.Child; }
set { border.Child = value; }
}
private void SetBorderMargin()
{
border.Margin = new Thickness(
BorderWidth, BorderWidth, BorderWidth, BorderWidth + ArrowSize.Height);
}
}
}

View file

@ -49,31 +49,24 @@
<Style TargetType="map:Pushpin" BasedOn="{StaticResource ContentControlStyle}">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Padding" Value="5,3"/>
<Setter Property="Padding" Value="7,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="map:Pushpin">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1">
<ContentPresenter Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}"/>
</Border>
<Path Grid.Row="1"
Data="M0.5,-1.2 L0.5,15 10,-1.2"
Fill="{TemplateBinding Background}"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="1"/>
</Grid>
<map:PushpinBorder
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderWidth="1"
CornerRadius="5">
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</map:PushpinBorder>
</ControlTemplate>
</Setter.Value>
</Setter>