mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Fixed clipping of WinUI/UWP MapPath
This commit is contained in:
parent
fd13503613
commit
a282ba1b5e
6 changed files with 101 additions and 26 deletions
|
|
@ -264,17 +264,7 @@ namespace MapControl
|
|||
|
||||
private static void ArrangeElement(FrameworkElement element, Point position)
|
||||
{
|
||||
var rect = new Rect(position.X, position.Y, 0d, 0d);
|
||||
|
||||
if (element.DesiredSize.Width >= 0d && element.DesiredSize.Width < double.PositiveInfinity)
|
||||
{
|
||||
rect.Width = element.DesiredSize.Width;
|
||||
}
|
||||
|
||||
if (element.DesiredSize.Height >= 0d && element.DesiredSize.Height < double.PositiveInfinity)
|
||||
{
|
||||
rect.Height = element.DesiredSize.Height;
|
||||
}
|
||||
var rect = new Rect(position, GetDesiredSize(element));
|
||||
|
||||
switch (element.HorizontalAlignment)
|
||||
{
|
||||
|
|
@ -309,17 +299,7 @@ namespace MapControl
|
|||
|
||||
private static void ArrangeElement(FrameworkElement element, Size parentSize)
|
||||
{
|
||||
var rect = new Rect();
|
||||
|
||||
if (element.DesiredSize.Width >= 0d && element.DesiredSize.Width < double.PositiveInfinity)
|
||||
{
|
||||
rect.Width = element.DesiredSize.Width;
|
||||
}
|
||||
|
||||
if (element.DesiredSize.Height >= 0d && element.DesiredSize.Height < double.PositiveInfinity)
|
||||
{
|
||||
rect.Height = element.DesiredSize.Height;
|
||||
}
|
||||
var rect = new Rect(new Point(), GetDesiredSize(element));
|
||||
|
||||
switch (element.HorizontalAlignment)
|
||||
{
|
||||
|
|
@ -391,5 +371,25 @@ namespace MapControl
|
|||
|
||||
element.Arrange(rect);
|
||||
}
|
||||
|
||||
internal static Size GetDesiredSize(UIElement element)
|
||||
{
|
||||
var width = 0d;
|
||||
var height = 0d;
|
||||
|
||||
if (element.DesiredSize.Width >= 0d &&
|
||||
element.DesiredSize.Width < double.PositiveInfinity)
|
||||
{
|
||||
width = element.DesiredSize.Width;
|
||||
}
|
||||
|
||||
if (element.DesiredSize.Height >= 0d &&
|
||||
element.DesiredSize.Height < double.PositiveInfinity)
|
||||
{
|
||||
height = element.DesiredSize.Height;
|
||||
}
|
||||
|
||||
return new Size(width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,6 +230,9 @@
|
|||
<Compile Include="..\WinUI\Animatable.WinUI.cs">
|
||||
<Link>Animatable.WinUI.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\WinUI\CanvasPanel.cs">
|
||||
<Link>CanvasPanel.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\WinUI\GeoImage.WinUI.cs">
|
||||
<Link>GeoImage.WinUI.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
|||
48
MapControl/WinUI/CanvasPanel.cs
Normal file
48
MapControl/WinUI/CanvasPanel.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// Copyright © 2023 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Linq;
|
||||
using Windows.Foundation;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Replacement for WinUI and UWP Canvas, which clips MapPath child elements.
|
||||
/// </summary>
|
||||
public class CanvasPanel : Panel
|
||||
{
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
|
||||
|
||||
foreach (var element in Children.OfType<UIElement>())
|
||||
{
|
||||
element.Measure(availableSize);
|
||||
}
|
||||
|
||||
return new Size();
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
foreach (var element in Children.OfType<UIElement>())
|
||||
{
|
||||
var x = Canvas.GetLeft(element);
|
||||
var y = Canvas.GetTop(element);
|
||||
var p = new Point(double.IsNaN(x) ? 0d : x, double.IsNaN(y) ? 0d : y);
|
||||
|
||||
element.Arrange(new Rect(p, MapPanel.GetDesiredSize(element)));
|
||||
}
|
||||
|
||||
return finalSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue