mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Remove OutlinedText from WPF sample app
This commit is contained in:
parent
dbbb4c3de3
commit
e16f404957
|
|
@ -70,8 +70,7 @@
|
|||
</Path.Data>
|
||||
</Path>
|
||||
<Grid Canvas.Left="15" Canvas.Top="-8">
|
||||
<local:OutlinedText Margin="1" OutlineThickness="1.5" Text="{Binding Name}"
|
||||
Background="{Binding Background, RelativeSource={RelativeSource AncestorType=map:MapBase}}"/>
|
||||
<TextBlock Margin="2,0" Text="{Binding Name}"/>
|
||||
</Grid>
|
||||
</Canvas>
|
||||
</ControlTemplate>
|
||||
|
|
@ -144,12 +143,14 @@
|
|||
<map:Pushpin AutoCollapse="True" Location="53.5,8.2" Content="N 53°30' E 8°12'"/>
|
||||
</map:Map>
|
||||
|
||||
<local:OutlinedText
|
||||
x:Name="mouseLocation" Margin="4" FontFamily="Consolas"
|
||||
Background="{Binding Background, ElementName=map}"
|
||||
Foreground="{Binding Foreground, ElementName=map}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Top"
|
||||
IsHitTestVisible="False"/>
|
||||
<TextBlock x:Name="mouseLocation"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Top" Margin="4" Padding="4,2"
|
||||
FontFamily="Consolas" IsHitTestVisible="False" Visibility="Collapsed"
|
||||
Foreground="{Binding Foreground, ElementName=map}">
|
||||
<TextBlock.Background>
|
||||
<SolidColorBrush Color="{Binding Background.Color, ElementName=map}" Opacity="0.5"/>
|
||||
</TextBlock.Background>
|
||||
</TextBlock>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#AFFFFFFF"
|
||||
DataContext="{Binding MapLayer, ElementName=map}">
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
using MapControl.Caching;
|
||||
using MapControl.UiTools;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -87,7 +86,7 @@ namespace SampleApplication
|
|||
{
|
||||
if (map.MapLayer is WmsImageLayer wmsLayer)
|
||||
{
|
||||
Debug.WriteLine(await wmsLayer.GetFeatureInfoAsync(e.GetPosition(map)));
|
||||
System.Diagnostics.Debug.WriteLine(await wmsLayer.GetFeatureInfoAsync(e.GetPosition(map)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -118,15 +117,18 @@ namespace SampleApplication
|
|||
"{0} {1:00} {2:00.000}\n{3} {4:000} {5:00.000}",
|
||||
latHemisphere, latitude / 60000, (latitude % 60000) / 1000d,
|
||||
lonHemisphere, longitude / 60000, (longitude % 60000) / 1000d);
|
||||
mouseLocation.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseLocation.Visibility = Visibility.Collapsed;
|
||||
mouseLocation.Text = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void MapMouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
mouseLocation.Visibility = Visibility.Collapsed;
|
||||
mouseLocation.Text = string.Empty;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,156 +0,0 @@
|
|||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace SampleApplication
|
||||
{
|
||||
public class OutlinedText : FrameworkElement
|
||||
{
|
||||
private FormattedText text;
|
||||
private Geometry outline;
|
||||
|
||||
public static readonly DependencyProperty TextProperty = TextBlock.TextProperty.AddOwner(
|
||||
typeof(OutlinedText),
|
||||
new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).text = null) { AffectsMeasure = true });
|
||||
|
||||
public static readonly DependencyProperty FontSizeProperty = TextBlock.FontSizeProperty.AddOwner(
|
||||
typeof(OutlinedText),
|
||||
new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).text = null) { AffectsMeasure = true });
|
||||
|
||||
public static readonly DependencyProperty FontFamilyProperty = TextBlock.FontFamilyProperty.AddOwner(
|
||||
typeof(OutlinedText),
|
||||
new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).text = null) { AffectsMeasure = true });
|
||||
|
||||
public static readonly DependencyProperty FontStyleProperty = TextBlock.FontStyleProperty.AddOwner(
|
||||
typeof(OutlinedText),
|
||||
new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).text = null) { AffectsMeasure = true });
|
||||
|
||||
public static readonly DependencyProperty FontWeightProperty = TextBlock.FontWeightProperty.AddOwner(
|
||||
typeof(OutlinedText),
|
||||
new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).text = null) { AffectsMeasure = true });
|
||||
|
||||
public static readonly DependencyProperty FontStretchProperty = TextBlock.FontStretchProperty.AddOwner(
|
||||
typeof(OutlinedText),
|
||||
new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).text = null) { AffectsMeasure = true });
|
||||
|
||||
public static readonly DependencyProperty ForegroundProperty = TextBlock.ForegroundProperty.AddOwner(
|
||||
typeof(OutlinedText),
|
||||
new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).text = null) { AffectsMeasure = true });
|
||||
|
||||
public static readonly DependencyProperty BackgroundProperty = TextBlock.BackgroundProperty.AddOwner(
|
||||
typeof(OutlinedText),
|
||||
new FrameworkPropertyMetadata(Brushes.White, (o, e) => ((OutlinedText)o).text = null) { AffectsMeasure = true });
|
||||
|
||||
public static readonly DependencyProperty OutlineThicknessProperty = DependencyProperty.Register(
|
||||
nameof(OutlineThickness), typeof(double), typeof(OutlinedText),
|
||||
new FrameworkPropertyMetadata(1d, FrameworkPropertyMetadataOptions.AffectsMeasure, (o, e) => ((OutlinedText)o).text = null));
|
||||
|
||||
public string Text
|
||||
{
|
||||
get { return (string)GetValue(TextProperty); }
|
||||
set { SetValue(TextProperty, value); }
|
||||
}
|
||||
|
||||
public double FontSize
|
||||
{
|
||||
get { return (double)GetValue(FontSizeProperty); }
|
||||
set { SetValue(FontSizeProperty, value); }
|
||||
}
|
||||
|
||||
public FontFamily FontFamily
|
||||
{
|
||||
get { return (FontFamily)GetValue(FontFamilyProperty); }
|
||||
set { SetValue(FontFamilyProperty, value); }
|
||||
}
|
||||
|
||||
public FontStyle FontStyle
|
||||
{
|
||||
get { return (FontStyle)GetValue(FontStyleProperty); }
|
||||
set { SetValue(FontStyleProperty, value); }
|
||||
}
|
||||
|
||||
public FontWeight FontWeight
|
||||
{
|
||||
get { return (FontWeight)GetValue(FontWeightProperty); }
|
||||
set { SetValue(FontWeightProperty, value); }
|
||||
}
|
||||
|
||||
public FontStretch FontStretch
|
||||
{
|
||||
get { return (FontStretch)GetValue(FontStretchProperty); }
|
||||
set { SetValue(FontStretchProperty, value); }
|
||||
}
|
||||
|
||||
public Brush Foreground
|
||||
{
|
||||
get { return (Brush)GetValue(ForegroundProperty); }
|
||||
set { SetValue(ForegroundProperty, value); }
|
||||
}
|
||||
|
||||
public Brush Background
|
||||
{
|
||||
get { return (Brush)GetValue(BackgroundProperty); }
|
||||
set { SetValue(BackgroundProperty, value); }
|
||||
}
|
||||
|
||||
public double OutlineThickness
|
||||
{
|
||||
get { return (double)GetValue(OutlineThicknessProperty); }
|
||||
set { SetValue(OutlineThicknessProperty, value); }
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
return ValidateText() ? outline.Bounds.Size : new Size();
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext)
|
||||
{
|
||||
if (ValidateText())
|
||||
{
|
||||
var location = outline.Bounds.Location;
|
||||
drawingContext.PushTransform(new TranslateTransform(-location.X, -location.Y));
|
||||
drawingContext.DrawGeometry(Background, null, outline);
|
||||
drawingContext.DrawText(text, new Point());
|
||||
}
|
||||
}
|
||||
|
||||
private bool ValidateText()
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
|
||||
|
||||
if (!typeface.TryGetGlyphTypeface(out GlyphTypeface glyphTypeface))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
text = new FormattedText(Text,
|
||||
CultureInfo.InvariantCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
typeface,
|
||||
FontSize,
|
||||
Foreground,
|
||||
VisualTreeHelper.GetDpi(this).PixelsPerDip);
|
||||
|
||||
outline = text.BuildGeometry(new Point()).GetWidenedPathGeometry(
|
||||
new Pen
|
||||
{
|
||||
Thickness = OutlineThickness * 2d,
|
||||
LineJoin = PenLineJoin.Round,
|
||||
StartLineCap = PenLineCap.Round,
|
||||
EndLineCap = PenLineCap.Round
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -38,10 +38,4 @@
|
|||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Runtime.Caching" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="..\Shared\TileLoader.cs">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Reference in a new issue