Added MapControl.UiTools.MapLayerInfo

This commit is contained in:
ClemensFischer 2025-09-16 14:18:29 +02:00
parent c31780a298
commit d23bc99f3d
16 changed files with 332 additions and 161 deletions

View file

@ -1,110 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Documents;
#elif UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Documents;
#else
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
#endif
namespace SampleApplication
{
public static class HyperlinkText
{
private static readonly Regex regex = new Regex(@"\[([^\]]+)\]\(([^\)]+)\)");
/// <summary>
/// Converts text containing hyperlinks in markdown syntax [text](url)
/// to a collection of Run and Hyperlink inlines.
/// </summary>
public static IEnumerable<Inline> TextToInlines(this string text)
{
var inlines = new List<Inline>();
while (!string.IsNullOrEmpty(text))
{
var match = regex.Match(text);
if (match.Success &&
match.Groups.Count == 3 &&
Uri.TryCreate(match.Groups[2].Value, UriKind.Absolute, out Uri uri))
{
inlines.Add(new Run { Text = text.Substring(0, match.Index) });
text = text.Substring(match.Index + match.Length);
var link = new Hyperlink { NavigateUri = uri };
link.Inlines.Add(new Run { Text = match.Groups[1].Value });
#if !WINUI && !UWP
link.ToolTip = uri.ToString();
link.RequestNavigate += (s, e) =>
{
try
{
Process.Start(new ProcessStartInfo(e.Uri.ToString()) { UseShellExecute = true });
}
catch (Exception ex)
{
Debug.WriteLine($"{e.Uri}: {ex}");
}
};
#endif
inlines.Add(link);
}
else
{
inlines.Add(new Run { Text = text });
text = null;
}
}
return inlines;
}
public static readonly DependencyProperty InlinesSourceProperty = DependencyProperty.RegisterAttached(
"InlinesSource", typeof(string), typeof(HyperlinkText), new PropertyMetadata(null, InlinesSourcePropertyChanged));
public static string GetInlinesSource(DependencyObject element)
{
return (string)element.GetValue(InlinesSourceProperty);
}
public static void SetInlinesSource(DependencyObject element, string value)
{
element.SetValue(InlinesSourceProperty, value);
}
private static void InlinesSourcePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
InlineCollection inlines = null;
if (obj is TextBlock block)
{
inlines = block.Inlines;
}
else if (obj is Paragraph paragraph)
{
inlines = paragraph.Inlines;
}
if (inlines != null)
{
inlines.Clear();
foreach (var inline in TextToInlines((string)e.NewValue))
{
inlines.Add(inline);
}
}
}
}
}

View file

@ -0,0 +1,44 @@
using System;
using System.Globalization;
#if WPF
using System.Windows;
using System.Windows.Data;
#elif UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
#elif WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
#else
using Avalonia.Data.Converters;
#endif
namespace SampleApplication
{
public class MapHeadingToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
#if AVALONIA
return (double)value != 0d;
#else
return (double)value != 0d ? Visibility.Visible : Visibility.Collapsed;
#endif
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Convert(value, targetType, parameter, culture.ToString());
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return ConvertBack(value, targetType, parameter, culture.ToString());
}
}
}

View file

@ -1,65 +0,0 @@
using System;
using System.ComponentModel;
using System.Globalization;
#if WINUI
using Microsoft.UI.Xaml.Data;
#elif UWP
using Windows.UI.Xaml.Data;
#elif AVALONIA
using Avalonia.Data.Converters;
#endif
namespace SampleApplication
{
public class DoubleTriggerConverter : IValueConverter
{
public double Trigger { get; set; }
public object TriggerValue { get; set; }
public object DefaultValue { get; set; }
public object Convert(object value, Type targetType, object parameter, string language)
{
var converter = TypeDescriptor.GetConverter(targetType);
return (double)value == Trigger ? converter.ConvertFrom(TriggerValue) : converter.ConvertFrom(DefaultValue);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Convert(value, targetType, parameter, "");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return ConvertBack(value, targetType, parameter, "");
}
}
public class MapHeadingToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return (double)value != 0d;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Convert(value, targetType, parameter, "");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return ConvertBack(value, targetType, parameter, "");
}
}
}