mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 14:08:32 +00:00
Added WinUI Sample Application
This commit is contained in:
parent
f8b0bcbeb1
commit
e138cb83ab
24 changed files with 421 additions and 99 deletions
62
SampleApps/WinUiApp/MainWindow.xaml.cs
Normal file
62
SampleApps/WinUiApp/MainWindow.xaml.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using MapControl;
|
||||
using MapControl.Caching;
|
||||
using Microsoft.UI.Xaml;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using ViewModel;
|
||||
|
||||
namespace WinUiApp
|
||||
{
|
||||
public sealed partial class MainWindow : Window
|
||||
{
|
||||
private readonly MapViewModel viewModel = new();
|
||||
|
||||
static MainWindow()
|
||||
{
|
||||
try
|
||||
{
|
||||
ImageLoader.HttpClient.DefaultRequestHeaders.Add("User-Agent", "XAML Map Control Test Application");
|
||||
|
||||
var appData = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl");
|
||||
|
||||
TileImageLoader.Cache = new ImageFileCache(Path.Combine(appData, "TileCache"));
|
||||
BingMapsTileLayer.ApiKey = File.ReadAllText(Path.Combine(appData, "BingMapsApiKey.txt"))?.Trim();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Title = "XAML Map Control - WinUI Sample Application";
|
||||
|
||||
root.DataContext = viewModel;
|
||||
|
||||
if (TileImageLoader.Cache is ImageFileCache cache)
|
||||
{
|
||||
Activated += async (s, e) =>
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
await cache.Clean();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private void SeamarksChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
map.Children.Insert(map.Children.IndexOf(graticule), viewModel.MapLayers.SeamarksLayer);
|
||||
}
|
||||
|
||||
private void SeamarksUnchecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
map.Children.Remove(viewModel.MapLayers.SeamarksLayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue