mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-13 10:25:05 +00:00
Avalonia 12
This commit is contained in:
parent
db9abd228d
commit
cf6131f59e
13 changed files with 89 additions and 64 deletions
|
|
@ -19,7 +19,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.3.13" />
|
||||
<PackageReference Include="Avalonia" Version="12.0.0" />
|
||||
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.3.13" />
|
||||
<PackageReference Include="Avalonia" Version="12.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="10.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.5" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace MapControl
|
|||
if (e.Pointer.Type != PointerType.Mouse &&
|
||||
ItemsControl.ItemsControlFromItemContainer(this) is MapItemsControl mapItemsControl)
|
||||
{
|
||||
mapItemsControl.UpdateSelection(this, e);
|
||||
mapItemsControl.UpdateSelectionFromEvent(this, e);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
|
|
@ -22,7 +22,7 @@ namespace MapControl
|
|||
e.InitialPressMouseButton == MouseButton.Left &&
|
||||
ItemsControl.ItemsControlFromItemContainer(this) is MapItemsControl mapItemsControl)
|
||||
{
|
||||
mapItemsControl.UpdateSelection(this, e);
|
||||
mapItemsControl.UpdateSelectionFromEvent(this, e);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
using Avalonia.Controls;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Presenters;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace MapControl
|
||||
|
|
@ -52,17 +54,22 @@ namespace MapControl
|
|||
ClearContainer((MapItem)container);
|
||||
}
|
||||
|
||||
internal void UpdateSelection(MapItem mapItem, PointerEventArgs e)
|
||||
protected override bool ShouldTriggerSelection(Visual selectable, PointerEventArgs eventArgs)
|
||||
{
|
||||
if (SelectionMode != SelectionMode.Single &&
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool UpdateSelectionFromEvent(UIElement container, RoutedEventArgs eventArgs)
|
||||
{
|
||||
if (SelectionMode == SelectionMode.Multiple &&
|
||||
eventArgs is PointerEventArgs e &&
|
||||
e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
||||
{
|
||||
SelectItemsInRange(mapItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateSelection(mapItem, true, false, e.KeyModifiers.HasFlag(KeyModifiers.Control));
|
||||
SelectItemsInRange((MapItem)container);
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.UpdateSelectionFromEvent(container, eventArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.3.13" />
|
||||
<PackageReference Include="Avalonia" Version="12.0.0" />
|
||||
<PackageReference Include="ProjNET" Version="2.1.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@
|
|||
<Setter Property="Padding" Value="4,0"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Right"/>
|
||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||
</Style>
|
||||
<Style Selector="ctxt|CRun">
|
||||
<Setter Property="FontSize" Value="10"/>
|
||||
</Style>
|
||||
</UserControl.Styles>
|
||||
|
|
@ -37,6 +35,8 @@
|
|||
</ProgressBar.IsVisible>
|
||||
</ProgressBar>
|
||||
|
||||
<md:MarkdownScrollViewer Markdown="{Binding MapLayer.Description}"/>
|
||||
<TextBlock
|
||||
VerticalAlignment="Center" Margin="{Binding Padding}"
|
||||
local:HyperlinkText.InlinesSource="{Binding MapLayer.Description}"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
|
|
|||
|
|
@ -4,16 +4,13 @@
|
|||
<DefineConstants>AVALONIA</DefineConstants>
|
||||
<RootNamespace>MapControl.UiTools</RootNamespace>
|
||||
<AssemblyTitle>XAML Map Control UI Tools Library for Avalonia UI</AssemblyTitle>
|
||||
<AvaloniaUseCompiledBindingsByDefault>false</AvaloniaUseCompiledBindingsByDefault>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Shared\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="..\Shared\HyperlinkText.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AvaloniaXaml Include="MapLayerInfo.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
|
@ -25,7 +22,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.3.13" />
|
||||
<PackageReference Include="Markdown.Avalonia.Tight" Version="11.0.2" />
|
||||
<PackageReference Include="Avalonia" Version="12.0.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,12 @@ using Microsoft.UI.Xaml.Documents;
|
|||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Documents;
|
||||
#elif AVALONIA
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Documents;
|
||||
using Avalonia.Media;
|
||||
using DependencyProperty = Avalonia.AvaloniaProperty;
|
||||
#endif
|
||||
|
||||
namespace MapControl.UiTools
|
||||
|
|
@ -38,14 +44,39 @@ namespace MapControl.UiTools
|
|||
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) });
|
||||
inlines.Add(new Run
|
||||
{
|
||||
Text = text.Substring(0, match.Index),
|
||||
#if WPF || AVALONIA
|
||||
BaselineAlignment = BaselineAlignment.Center
|
||||
#endif
|
||||
});
|
||||
|
||||
text = text.Substring(match.Index + match.Length);
|
||||
|
||||
var link = new Hyperlink { NavigateUri = uri };
|
||||
link.Inlines.Add(new Run { Text = match.Groups[1].Value });
|
||||
#if WPF
|
||||
link.ToolTip = uri.ToString();
|
||||
var hyperlinkText = match.Groups[1].Value;
|
||||
#if AVALONIA
|
||||
var button = new HyperlinkButton
|
||||
{
|
||||
Content = hyperlinkText,
|
||||
NavigateUri = uri,
|
||||
Padding = new Thickness(0),
|
||||
Margin = new Thickness(0)
|
||||
};
|
||||
|
||||
var link = new InlineUIContainer
|
||||
{
|
||||
Child = button,
|
||||
BaselineAlignment = BaselineAlignment.Center
|
||||
};
|
||||
#else
|
||||
var run = new Run { Text = hyperlinkText };
|
||||
var link = new Hyperlink { NavigateUri = uri };
|
||||
link.Inlines.Add(run);
|
||||
#if WPF
|
||||
run.BaselineAlignment = BaselineAlignment.Center;
|
||||
link.BaselineAlignment = BaselineAlignment.Center;
|
||||
link.ToolTip = uri.ToString();
|
||||
link.RequestNavigate += (_, e) =>
|
||||
{
|
||||
try
|
||||
|
|
@ -57,6 +88,7 @@ namespace MapControl.UiTools
|
|||
Debug.WriteLine($"{e.Uri}: {ex}");
|
||||
}
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
inlines.Add(link);
|
||||
}
|
||||
|
|
@ -70,41 +102,29 @@ namespace MapControl.UiTools
|
|||
return inlines;
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty InlinesSourceProperty = DependencyProperty.RegisterAttached(
|
||||
"InlinesSource", typeof(string), typeof(HyperlinkText), new PropertyMetadata(null, InlinesSourcePropertyChanged));
|
||||
public static readonly DependencyProperty InlinesSourceProperty =
|
||||
DependencyPropertyHelper.RegisterAttached<string>("InlinesSource", typeof(HyperlinkText), null,
|
||||
(element, oldValue, newValue) =>
|
||||
{
|
||||
if (element is TextBlock textBlock)
|
||||
{
|
||||
textBlock.Inlines.Clear();
|
||||
|
||||
public static string GetInlinesSource(DependencyObject element)
|
||||
foreach (var inline in TextToInlines(newValue))
|
||||
{
|
||||
textBlock.Inlines.Add(inline);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public static string GetInlinesSource(TextBlock element)
|
||||
{
|
||||
return (string)element.GetValue(InlinesSourceProperty);
|
||||
}
|
||||
|
||||
public static void SetInlinesSource(DependencyObject element, string value)
|
||||
public static void SetInlinesSource(TextBlock 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Windows.UI.Xaml.Controls;
|
|||
#elif WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
#else
|
||||
#elif AVALONIA
|
||||
using Avalonia.Controls;
|
||||
using DependencyProperty = Avalonia.AvaloniaProperty;
|
||||
using FrameworkElement = Avalonia.Controls.Control;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using Windows.UI.Xaml.Markup;
|
|||
#elif WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
#else
|
||||
#elif AVALONIA
|
||||
using Avalonia.Metadata;
|
||||
using FrameworkElement = Avalonia.Controls.Control;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.Windows.Markup;
|
|||
using Windows.UI.Xaml.Markup;
|
||||
#elif WINUI
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
#else
|
||||
#elif AVALONIA
|
||||
using Avalonia.Metadata;
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using Windows.UI.Xaml.Controls;
|
|||
#elif WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
#else
|
||||
#elif AVALONIA
|
||||
using Avalonia.Controls;
|
||||
using DependencyProperty = Avalonia.AvaloniaProperty;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<DefineConstants>AVALONIA</DefineConstants>
|
||||
<RootNamespace>SampleApplication</RootNamespace>
|
||||
<AssemblyTitle>XAML Map Control Avalonia Sample Application</AssemblyTitle>
|
||||
<AvaloniaUseCompiledBindingsByDefault>false</AvaloniaUseCompiledBindingsByDefault>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -28,11 +29,12 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.3.13" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.3.13" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.13" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.13" />
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.13" />
|
||||
<PackageReference Include="Avalonia" Version="12.0.0" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="12.0.0" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="12.0.0" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.5" />
|
||||
<!-- avoid package vulnerability warning, will be fixed with Avalonia 12.0.1 -->
|
||||
<PackageReference Include="Tmds.DBus.Protocol" Version="0.92.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue