File scoped namespaces

This commit is contained in:
ClemensFischer 2026-04-13 17:14:49 +02:00
parent c14377f976
commit 65aba44af6
152 changed files with 11962 additions and 12115 deletions

View file

@ -2,33 +2,32 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace SampleApplication
namespace SampleApplication;
public sealed partial class App : Application
{
public sealed partial class App : Application
public App()
{
public App()
InitializeComponent();
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
if (Window.Current.Content is not Frame rootFrame)
{
InitializeComponent();
rootFrame = new Frame();
Window.Current.Content = rootFrame;
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
if (e.PrelaunchActivated == false)
{
if (Window.Current.Content is not Frame rootFrame)
if (rootFrame.Content == null)
{
rootFrame = new Frame();
Window.Current.Content = rootFrame;
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
if (e.PrelaunchActivated == false)
{
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
Window.Current.Activate();
}
Window.Current.Activate();
}
}
}

View file

@ -10,146 +10,145 @@ using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
namespace SampleApplication
namespace SampleApplication;
public sealed partial class MainPage : Page
{
public sealed partial class MainPage : Page
public MainPage()
{
public MainPage()
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control UWP Sample Application");
var loggerFactory = LoggerFactory.Create(builder => builder.AddDebug().SetMinimumLevel(LogLevel.Information));
ImageLoader.LoggerFactory = loggerFactory;
var tileCache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder, loggerFactory);
TileImageLoader.Cache = tileCache;
Unloaded += (s, e) => tileCache.Dispose();
InitializeComponent();
AddTestLayers();
}
partial void AddTestLayers();
private void MapItemsControlSelectionChanged(object sender, SelectionChangedEventArgs e)
{
Debug.WriteLine("SelectedItems: " + string.Join(", ", ((MapItemsControl)sender).SelectedItems.OfType<PointItem>().Select(item => item.Name)));
}
private void MapDoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
if (e.OriginalSource is Map map)
{
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control UWP Sample Application");
var loggerFactory = LoggerFactory.Create(builder => builder.AddDebug().SetMinimumLevel(LogLevel.Information));
ImageLoader.LoggerFactory = loggerFactory;
var tileCache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheFolder, loggerFactory);
TileImageLoader.Cache = tileCache;
Unloaded += (s, e) => tileCache.Dispose();
InitializeComponent();
AddTestLayers();
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
}
}
partial void AddTestLayers();
private void ResetHeadingButtonClick(object sender, RoutedEventArgs e)
{
map.TargetHeading = 0d;
}
private void MapItemsControlSelectionChanged(object sender, SelectionChangedEventArgs e)
private async void MapPointerPressed(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
{
Debug.WriteLine("SelectedItems: " + string.Join(", ", ((MapItemsControl)sender).SelectedItems.OfType<PointItem>().Select(item => item.Name)));
}
var point = e.GetCurrentPoint(map);
private void MapDoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
if (e.OriginalSource is Map map)
if (point.Properties.IsRightButtonPressed && map.CapturePointer(e.Pointer))
{
map.TargetCenter = map.ViewToLocation(e.GetPosition(map));
}
}
var location = map.ViewToLocation(point.Position);
private void ResetHeadingButtonClick(object sender, RoutedEventArgs e)
{
map.TargetHeading = 0d;
}
private async void MapPointerPressed(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
{
var point = e.GetCurrentPoint(map);
if (point.Properties.IsRightButtonPressed && map.CapturePointer(e.Pointer))
if (location != null)
{
var location = map.ViewToLocation(point.Position);
if (location != null)
{
measurementLine.Visibility = Visibility.Visible;
measurementLine.Locations = new LocationCollection(location);
}
}
else if (e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control) && map.MapLayer is WmsImageLayer wmsLayer)
{
Debug.WriteLine(await wmsLayer.GetFeatureInfoAsync(point.Position));
measurementLine.Visibility = Visibility.Visible;
measurementLine.Locations = new LocationCollection(location);
}
}
else if (e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control) && map.MapLayer is WmsImageLayer wmsLayer)
{
Debug.WriteLine(await wmsLayer.GetFeatureInfoAsync(point.Position));
}
}
}
private void MapPointerReleased(object sender, PointerRoutedEventArgs e)
private void MapPointerReleased(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
{
map.ReleasePointerCapture(e.Pointer);
measurementLine.Visibility = Visibility.Collapsed;
measurementLine.Locations = null;
}
map.ReleasePointerCapture(e.Pointer);
measurementLine.Visibility = Visibility.Collapsed;
measurementLine.Locations = null;
}
}
private void MapPointerMoved(object sender, PointerRoutedEventArgs e)
private void MapPointerMoved(object sender, PointerRoutedEventArgs e)
{
var location = map.ViewToLocation(e.GetCurrentPoint(map).Position);
if (location != null)
{
var location = map.ViewToLocation(e.GetCurrentPoint(map).Position);
mouseLocation.Visibility = Visibility.Visible;
mouseLocation.Text = GetLatLonText(location);
if (location != null)
var start = measurementLine.Locations?.FirstOrDefault();
if (start != null)
{
mouseLocation.Visibility = Visibility.Visible;
mouseLocation.Text = GetLatLonText(location);
var start = measurementLine.Locations?.FirstOrDefault();
if (start != null)
{
measurementLine.Locations = LocationCollection.GeodesicLocations(start, location);
mouseLocation.Text += GetDistanceText(location.GetDistance(start));
}
}
else
{
mouseLocation.Visibility = Visibility.Collapsed;
mouseLocation.Text = "";
measurementLine.Locations = LocationCollection.GeodesicLocations(start, location);
mouseLocation.Text += GetDistanceText(location.GetDistance(start));
}
}
private void MapPointerExited(object sender, PointerRoutedEventArgs e)
else
{
mouseLocation.Visibility = Visibility.Collapsed;
mouseLocation.Text = "";
}
}
private static string GetLatLonText(Location location)
private void MapPointerExited(object sender, PointerRoutedEventArgs e)
{
mouseLocation.Visibility = Visibility.Collapsed;
mouseLocation.Text = "";
}
private static string GetLatLonText(Location location)
{
var latitude = (int)Math.Round(location.Latitude * 60000d);
var longitude = (int)Math.Round(Location.NormalizeLongitude(location.Longitude) * 60000d);
var latHemisphere = 'N';
var lonHemisphere = 'E';
if (latitude < 0)
{
var latitude = (int)Math.Round(location.Latitude * 60000d);
var longitude = (int)Math.Round(Location.NormalizeLongitude(location.Longitude) * 60000d);
var latHemisphere = 'N';
var lonHemisphere = 'E';
if (latitude < 0)
{
latitude = -latitude;
latHemisphere = 'S';
}
if (longitude < 0)
{
longitude = -longitude;
lonHemisphere = 'W';
}
return string.Format(CultureInfo.InvariantCulture,
"{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);
latitude = -latitude;
latHemisphere = 'S';
}
private static string GetDistanceText(double distance)
if (longitude < 0)
{
var unit = "m";
if (distance >= 1000d)
{
distance /= 1000d;
unit = "km";
}
var distanceFormat = distance >= 100d ? "F0" : "F1";
return string.Format(CultureInfo.InvariantCulture, "\n {0:" + distanceFormat + "} {1}", distance, unit);
longitude = -longitude;
lonHemisphere = 'W';
}
return string.Format(CultureInfo.InvariantCulture,
"{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);
}
private static string GetDistanceText(double distance)
{
var unit = "m";
if (distance >= 1000d)
{
distance /= 1000d;
unit = "km";
}
var distanceFormat = distance >= 100d ? "F0" : "F1";
return string.Format(CultureInfo.InvariantCulture, "\n {0:" + distanceFormat + "} {1}", distance, unit);
}
}