From e16f404957169a8a990eaf5bb8c1f0a9dcbaae0c Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Thu, 5 Jan 2023 15:37:43 +0100 Subject: [PATCH] Remove OutlinedText from WPF sample app --- SampleApps/WpfApplication/MainWindow.xaml | 17 +- SampleApps/WpfApplication/MainWindow.xaml.cs | 6 +- SampleApps/WpfApplication/OutlinedText.cs | 156 ------------------ .../WpfApplication/WpfApplication.csproj | 8 +- 4 files changed, 14 insertions(+), 173 deletions(-) delete mode 100644 SampleApps/WpfApplication/OutlinedText.cs diff --git a/SampleApps/WpfApplication/MainWindow.xaml b/SampleApps/WpfApplication/MainWindow.xaml index bf3ed7d8..05b44d76 100644 --- a/SampleApps/WpfApplication/MainWindow.xaml +++ b/SampleApps/WpfApplication/MainWindow.xaml @@ -70,8 +70,7 @@ - + @@ -144,12 +143,14 @@ - + + + + + diff --git a/SampleApps/WpfApplication/MainWindow.xaml.cs b/SampleApps/WpfApplication/MainWindow.xaml.cs index b386f91f..c09df8fc 100644 --- a/SampleApps/WpfApplication/MainWindow.xaml.cs +++ b/SampleApps/WpfApplication/MainWindow.xaml.cs @@ -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; } diff --git a/SampleApps/WpfApplication/OutlinedText.cs b/SampleApps/WpfApplication/OutlinedText.cs deleted file mode 100644 index 0971cf6f..00000000 --- a/SampleApps/WpfApplication/OutlinedText.cs +++ /dev/null @@ -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; - } - } -} diff --git a/SampleApps/WpfApplication/WpfApplication.csproj b/SampleApps/WpfApplication/WpfApplication.csproj index 9a2d260b..4879684a 100644 --- a/SampleApps/WpfApplication/WpfApplication.csproj +++ b/SampleApps/WpfApplication/WpfApplication.csproj @@ -38,10 +38,4 @@ - - - - Never - - - \ No newline at end of file +