mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 22:18:56 +00:00
Version 2.4.2.:
- added HyperlinkText.InlinesSource attached property - simplified TileLayerCollection, removed it from MapBase - simplified MapRectangle and MapImage
This commit is contained in:
parent
1583b10ff3
commit
f6a881c674
36 changed files with 456 additions and 372 deletions
|
|
@ -8,80 +8,81 @@
|
|||
Title="XAML MapControl - WPF Test Application" Height="600" Width="800"
|
||||
Stylus.IsPressAndHoldEnabled="False">
|
||||
<Window.Resources>
|
||||
<map:TileLayerCollection x:Key="TileLayers">
|
||||
<!--
|
||||
TileLayers with OpenStreetMap data.
|
||||
-->
|
||||
<map:TileLayer SourceName="OpenStreetMap"
|
||||
Description="Maps © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
MaxZoomLevel="19"/>
|
||||
<map:TileLayer SourceName="Thunderforest OpenCycleMap"
|
||||
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png"/>
|
||||
<map:TileLayer SourceName="Thunderforest Landscape"
|
||||
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png"/>
|
||||
<map:TileLayer SourceName="Thunderforest Outdoors"
|
||||
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png"/>
|
||||
<map:TileLayer SourceName="Thunderforest Transport"
|
||||
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.thunderforest.com/transport/{z}/{x}/{y}.png"/>
|
||||
<map:TileLayer SourceName="Thunderforest Transport Dark"
|
||||
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.thunderforest.com/transport-dark/{z}/{x}/{y}.png"
|
||||
Foreground="White" Background="Black"/>
|
||||
<map:TileLayer SourceName="MapQuest OpenStreetMap"
|
||||
Description="Maps © [MapQuest](http://www.mapquest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://otile{n}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png"
|
||||
MaxZoomLevel="19"/>
|
||||
<map:TileLayer SourceName="Seamarks"
|
||||
TileSource="http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png"
|
||||
MinZoomLevel="9" MaxZoomLevel="18"/>
|
||||
<!--
|
||||
TileLayers with OpenStreetMap data.
|
||||
-->
|
||||
<map:TileLayer x:Key="OpenStreetMap" SourceName="OpenStreetMap"
|
||||
Description="Maps © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
MaxZoomLevel="19"/>
|
||||
<map:TileLayer x:Key="OpenCycleMap" SourceName="Thunderforest OpenCycleMap"
|
||||
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png"/>
|
||||
<map:TileLayer x:Key="Landscape" SourceName="Thunderforest Landscape"
|
||||
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png"/>
|
||||
<map:TileLayer x:Key="Outdoors" SourceName="Thunderforest Outdoors"
|
||||
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png"/>
|
||||
<map:TileLayer x:Key="Transport" SourceName="Thunderforest Transport"
|
||||
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.thunderforest.com/transport/{z}/{x}/{y}.png"/>
|
||||
<map:TileLayer x:Key="TransportDark" SourceName="Thunderforest Transport Dark"
|
||||
Description="Maps © [Thunderforest](http://www.thunderforest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://{c}.tile.thunderforest.com/transport-dark/{z}/{x}/{y}.png"
|
||||
Foreground="White" Background="Black"/>
|
||||
<map:TileLayer x:Key="MapQuest" SourceName="MapQuest OpenStreetMap"
|
||||
Description="Maps © [MapQuest](http://www.mapquest.com/), Data © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://otile{n}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png"
|
||||
MaxZoomLevel="19"/>
|
||||
<map:TileLayer x:Key="Seamarks" SourceName="Seamarks"
|
||||
TileSource="http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png"
|
||||
MinZoomLevel="9" MaxZoomLevel="18"/>
|
||||
|
||||
<!--
|
||||
Bing Maps TileLayers with tile URLs retrieved from the Imagery Metadata Service
|
||||
(see http://msdn.microsoft.com/en-us/library/ff701716.aspx).
|
||||
A Bing Maps API Key (see http://msdn.microsoft.com/en-us/library/ff428642.aspx) is required
|
||||
for using these layers and must be assigned to the static BingMapsTileLayer.ApiKey property.
|
||||
-->
|
||||
<map:BingMapsTileLayer SourceName="Bing Maps Road"
|
||||
Description="© [Microsoft Corporation](http://www.bing.com/maps/)"
|
||||
Mode="Road" MaxZoomLevel="19"/>
|
||||
<map:BingMapsTileLayer SourceName="Bing Maps Aerial"
|
||||
Description="© [Microsoft Corporation](http://www.bing.com/maps/)"
|
||||
Mode="Aerial" MaxZoomLevel="19" Foreground="White" Background="Black"/>
|
||||
<map:BingMapsTileLayer SourceName="Bing Maps Hybrid"
|
||||
Description="© [Microsoft Corporation](http://www.bing.com/maps/)"
|
||||
Mode="AerialWithLabels" MaxZoomLevel="19" Foreground="White" Background="Black"/>
|
||||
<!--
|
||||
Bing Maps TileLayers with tile URLs retrieved from the Imagery Metadata Service
|
||||
(see http://msdn.microsoft.com/en-us/library/ff701716.aspx).
|
||||
A Bing Maps API Key (see http://msdn.microsoft.com/en-us/library/ff428642.aspx) is required
|
||||
for using these layers and must be assigned to the static BingMapsTileLayer.ApiKey property.
|
||||
-->
|
||||
<map:BingMapsTileLayer x:Key="BingRoad" SourceName="Bing Maps Road"
|
||||
Description="© [Microsoft Corporation](http://www.bing.com/maps/)"
|
||||
Mode="Road" MaxZoomLevel="19"/>
|
||||
<map:BingMapsTileLayer x:Key="BingAerial" SourceName="Bing Maps Aerial"
|
||||
Description="© [Microsoft Corporation](http://www.bing.com/maps/)"
|
||||
Mode="Aerial" MaxZoomLevel="19" Foreground="White" Background="Black"/>
|
||||
<map:BingMapsTileLayer x:Key="BingHybrid" SourceName="Bing Maps Hybrid"
|
||||
Description="© [Microsoft Corporation](http://www.bing.com/maps/)"
|
||||
Mode="AerialWithLabels" MaxZoomLevel="19" Foreground="White" Background="Black"/>
|
||||
|
||||
<!--
|
||||
A TileLayer for World OSM WMS, a Web Map Service based on OpenStreetMap data.
|
||||
-->
|
||||
<!--<map:TileLayer SourceName="World OSM WMS"
|
||||
Description="[World OSM WMS](http://www.osm-wms.de/) © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://129.206.228.72/cached/osm?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=osm_auto:all&STYLES=&SRS=EPSG:900913&BBOX={W},{S},{E},{N}&WIDTH=256&HEIGHT=256&FORMAT=image/png"/>-->
|
||||
<!--
|
||||
A TileLayer for World OSM WMS, a Web Map Service based on OpenStreetMap data.
|
||||
-->
|
||||
<!--<map:TileLayer x:Key="WorldOsm" SourceName="World OSM WMS"
|
||||
Description="[World OSM WMS](http://www.osm-wms.de/) © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="http://129.206.228.72/cached/osm?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=osm_auto:all&STYLES=&SRS=EPSG:900913&BBOX={W},{S},{E},{N}&WIDTH=256&HEIGHT=256&FORMAT=image/png"/>-->
|
||||
|
||||
<!--
|
||||
A TileLayer that uses an ImageTileSource, which bypasses caching of map tile images
|
||||
-->
|
||||
<!--<map:TileLayer SourceName="OpenStreetMap No Cache"
|
||||
Description="© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)">
|
||||
<map:ImageTileSource IsAsync="True" UriFormat="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"/>
|
||||
</map:TileLayer>-->
|
||||
<!--
|
||||
A TileLayer that uses an ImageTileSource
|
||||
-->
|
||||
<!--<map:TileLayer x:Key="OsmImageTileSource"
|
||||
Description="© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)">
|
||||
<map:ImageTileSource IsAsync="True" UriFormat="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"/>
|
||||
</map:TileLayer>-->
|
||||
|
||||
<!--
|
||||
A TileLayer that demonstrates how to access local tile image files (from ImageFileCache here)
|
||||
-->
|
||||
<!--<map:TileLayer x:Key="OsmLocalFiles"
|
||||
Description="© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="file:///C:/ProgramData/MapControl/TileCache/OpenStreetMap/{z}/{x}/{y}.png"/>-->
|
||||
|
||||
<!--
|
||||
A TileLayer that demonstrates how to access local tile image files (from ImageFileCache here)
|
||||
-->
|
||||
<!--<map:TileLayer SourceName="OSM Local Files"
|
||||
Description="© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
TileSource="file:///C:/ProgramData/MapControl/TileCache/OpenStreetMap/{z}/{x}/{y}.png"/>-->
|
||||
</map:TileLayerCollection>
|
||||
<local:LocationToVisibilityConverter x:Key="LocationToVisibilityConverter"/>
|
||||
|
||||
<DataTemplate x:Key="PolylineItemTemplate">
|
||||
<map:MapPolyline Locations="{Binding Locations}" Stroke="Red" StrokeThickness="3"/>
|
||||
</DataTemplate>
|
||||
|
||||
<Style x:Key="PolylineItemStyle" TargetType="map:MapItem">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
|
|
@ -91,6 +92,7 @@
|
|||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="PointItemStyle" TargetType="map:MapItem">
|
||||
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
||||
<Setter Property="Foreground" Value="Black"/>
|
||||
|
|
@ -104,7 +106,7 @@
|
|||
<VisualState x:Name="Disabled"/>
|
||||
<VisualState x:Name="MouseOver">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="labelBackground" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.1"/>
|
||||
<DoubleAnimation Storyboard.TargetName="labelBackground" Storyboard.TargetProperty="Opacity" To="0.7" Duration="0:0:0.1"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
|
|
@ -131,8 +133,8 @@
|
|||
</Path.Data>
|
||||
</Path>
|
||||
<Grid Canvas.Left="15" Canvas.Top="-8">
|
||||
<Rectangle x:Name="labelBackground" Fill="White" Opacity="0.7"/>
|
||||
<TextBlock Margin="2,0,2,0" Text="{Binding Name}"/>
|
||||
<Rectangle x:Name="labelBackground" Fill="White" Opacity="0"/>
|
||||
<local:OutlinedText Margin="1" OutlineThickness="1.5" Text="{Binding Name}"/>
|
||||
</Grid>
|
||||
</Canvas>
|
||||
</ControlTemplate>
|
||||
|
|
@ -140,6 +142,7 @@
|
|||
</Setter>
|
||||
<EventSetter Event="TouchDown" Handler="MapItemTouchDown"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="PushpinItemStyle" TargetType="map:MapItem">
|
||||
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
||||
<Setter Property="Visibility">
|
||||
|
|
@ -166,15 +169,18 @@
|
|||
</Style.Triggers>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Window.DataContext>
|
||||
<vm:ViewModel/>
|
||||
</Window.DataContext>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<map:Map x:Name="map" Center="{Binding MapCenter}" ZoomLevel="11" MaxZoomLevel="20"
|
||||
<map:Map x:Name="map" ZoomLevel="11" MaxZoomLevel="20" Center="{Binding MapCenter}"
|
||||
TileLayer="{StaticResource OpenStreetMap}"
|
||||
MouseLeftButtonDown="MapMouseLeftButtonDown" MouseRightButtonDown="MapMouseRightButtonDown"
|
||||
MouseMove="MapMouseMove" MouseLeave="MapMouseLeave"
|
||||
ManipulationInertiaStarting="MapManipulationInertiaStarting">
|
||||
|
|
@ -223,7 +229,7 @@
|
|||
</map:Map>
|
||||
|
||||
<Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#7FFFFFFF">
|
||||
<TextBlock x:Name="mapLegend" Margin="2" FontSize="10"/>
|
||||
<TextBlock Margin="2" FontSize="10" map:HyperlinkText.InlinesSource="{Binding TileLayer.Description, ElementName=map}"/>
|
||||
</Border>
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
|
|
@ -252,18 +258,18 @@
|
|||
</StackPanel>
|
||||
<CheckBox ToolTip="Seamarks Overlay" Margin="7" VerticalAlignment="Bottom" Content="Seamarks"
|
||||
Checked="SeamarksChecked" Unchecked="SeamarksUnchecked"/>
|
||||
<ComboBox x:Name="tileLayerComboBox" ToolTip="Tile Layer" Margin="5" VerticalAlignment="Bottom"
|
||||
SelectionChanged="TileLayerSelectionChanged">
|
||||
<ComboBoxItem Tag="OpenStreetMap">OpenStreetMap</ComboBoxItem>
|
||||
<ComboBoxItem Tag="Thunderforest OpenCycleMap">OpenCycleMap</ComboBoxItem>
|
||||
<ComboBoxItem Tag="Thunderforest Landscape">Landscape</ComboBoxItem>
|
||||
<ComboBoxItem Tag="Thunderforest Outdoors">Outdoors</ComboBoxItem>
|
||||
<ComboBoxItem Tag="Thunderforest Transport">Transport</ComboBoxItem>
|
||||
<ComboBoxItem Tag="Thunderforest Transport Dark">Transport Dark</ComboBoxItem>
|
||||
<ComboBoxItem Tag="MapQuest OpenStreetMap">MapQuest Open</ComboBoxItem>
|
||||
<!--<ComboBoxItem Tag="Bing Maps Road">Bing Maps Road</ComboBoxItem>
|
||||
<ComboBoxItem Tag="Bing Maps Aerial">Bing Maps Aerial</ComboBoxItem>
|
||||
<ComboBoxItem Tag="Bing Maps Hybrid">Bing Maps Hybrid</ComboBoxItem>-->
|
||||
<ComboBox ToolTip="Tile Layer" Margin="5" VerticalAlignment="Bottom"
|
||||
SelectedValuePath="Tag" SelectedValue="{Binding TileLayer, ElementName=map, Mode=TwoWay}">
|
||||
<ComboBoxItem Tag="{StaticResource OpenStreetMap}">OpenStreetMap</ComboBoxItem>
|
||||
<ComboBoxItem Tag="{StaticResource OpenCycleMap}">OpenCycleMap</ComboBoxItem>
|
||||
<ComboBoxItem Tag="{StaticResource Landscape}">Landscape</ComboBoxItem>
|
||||
<ComboBoxItem Tag="{StaticResource Outdoors}">Outdoors</ComboBoxItem>
|
||||
<ComboBoxItem Tag="{StaticResource Transport}">Transport</ComboBoxItem>
|
||||
<ComboBoxItem Tag="{StaticResource TransportDark}">Transport Dark</ComboBoxItem>
|
||||
<ComboBoxItem Tag="{StaticResource MapQuest}">MapQuest Open</ComboBoxItem>
|
||||
<!--<ComboBoxItem Tag="{StaticResource BingRoad}">Bing Maps Road</ComboBoxItem>
|
||||
<ComboBoxItem Tag="{StaticResource BingAerial}">Bing Maps Aerial</ComboBoxItem>
|
||||
<ComboBoxItem Tag="{StaticResource BingHybrid}">Bing Maps Hybrid</ComboBoxItem>-->
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -1,28 +1,21 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using MapControl;
|
||||
using MapControl.Caching;
|
||||
|
||||
namespace WpfApplication
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private TileLayerCollection tileLayers;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
//TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheName, TileImageLoader.DefaultCacheFolder);
|
||||
//TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheName, TileImageLoader.DefaultCacheFolder);
|
||||
//TileImageLoader.Cache = new MapControl.Caching.ImageFileCache(TileImageLoader.DefaultCacheName, TileImageLoader.DefaultCacheFolder);
|
||||
//TileImageLoader.Cache = new MapControl.Caching.FileDbCache(TileImageLoader.DefaultCacheName, TileImageLoader.DefaultCacheFolder);
|
||||
//TileImageLoader.HttpUserAgent = "...";
|
||||
//BingMapsTileLayer.ApiKey = "...";
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
tileLayers = (TileLayerCollection)Resources["TileLayers"];
|
||||
tileLayerComboBox.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
private void MapMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
|
|
@ -85,24 +78,14 @@ namespace WpfApplication
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void TileLayerSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
var selectedItem = (ComboBoxItem)tileLayerComboBox.SelectedItem;
|
||||
|
||||
map.TileLayer = tileLayers[(string)selectedItem.Tag];
|
||||
|
||||
mapLegend.Inlines.Clear();
|
||||
mapLegend.Inlines.AddRange(map.TileLayer.DescriptionInlines);
|
||||
}
|
||||
|
||||
private void SeamarksChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
map.TileLayers.Add(tileLayers["Seamarks"]);
|
||||
map.TileLayers.Add((TileLayer)Resources["Seamarks"]);
|
||||
}
|
||||
|
||||
private void SeamarksUnchecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
map.TileLayers.Remove(tileLayers["Seamarks"]);
|
||||
map.TileLayers.Remove((TileLayer)Resources["Seamarks"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
145
SampleApps/WpfApplication/OutlinedText.cs
Normal file
145
SampleApps/WpfApplication/OutlinedText.cs
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace WpfApplication
|
||||
{
|
||||
public class OutlinedText : FrameworkElement
|
||||
{
|
||||
private GlyphRun glyphRun;
|
||||
private Geometry outline;
|
||||
|
||||
public static readonly DependencyProperty TextProperty = TextBlock.TextProperty.AddOwner(
|
||||
typeof(OutlinedText), new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).glyphRun = null));
|
||||
|
||||
public static readonly DependencyProperty FontSizeProperty = TextBlock.FontSizeProperty.AddOwner(
|
||||
typeof(OutlinedText), new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).glyphRun = null));
|
||||
|
||||
public static readonly DependencyProperty FontFamilyProperty = TextBlock.FontFamilyProperty.AddOwner(
|
||||
typeof(OutlinedText), new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).glyphRun = null));
|
||||
|
||||
public static readonly DependencyProperty FontStyleProperty = TextBlock.FontStyleProperty.AddOwner(
|
||||
typeof(OutlinedText), new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).glyphRun = null));
|
||||
|
||||
public static readonly DependencyProperty FontWeightProperty = TextBlock.FontWeightProperty.AddOwner(
|
||||
typeof(OutlinedText), new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).glyphRun = null));
|
||||
|
||||
public static readonly DependencyProperty FontStretchProperty = TextBlock.FontStretchProperty.AddOwner(
|
||||
typeof(OutlinedText), new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).glyphRun = null));
|
||||
|
||||
public static readonly DependencyProperty ForegroundProperty = TextBlock.ForegroundProperty.AddOwner(
|
||||
typeof(OutlinedText), new FrameworkPropertyMetadata((o, e) => ((OutlinedText)o).glyphRun = null));
|
||||
|
||||
public static readonly DependencyProperty BackgroundProperty = TextBlock.BackgroundProperty.AddOwner(
|
||||
typeof(OutlinedText), new FrameworkPropertyMetadata(Brushes.White, (o, e) => ((OutlinedText)o).glyphRun = null));
|
||||
|
||||
public static readonly DependencyProperty OutlineThicknessProperty = DependencyProperty.Register(
|
||||
"OutlineThickness", typeof(double), typeof(OutlinedText),
|
||||
new FrameworkPropertyMetadata(1d, FrameworkPropertyMetadataOptions.AffectsMeasure, (o, e) => ((OutlinedText)o).glyphRun = null));
|
||||
|
||||
public string Text
|
||||
{
|
||||
get { return (string)GetValue(TextProperty); }
|
||||
set { SetValue(TextProperty, value); }
|
||||
}
|
||||
|
||||
public double FontSize
|
||||
{
|
||||
get { return (double)GetValue(FontSizeProperty); }
|
||||
set { SetValue(FontSizeProperty, value); }
|
||||
}
|
||||
|
||||
public FontFamily FontFamily
|
||||
{
|
||||
get { return (FontFamily)GetValue(FontFamilyProperty); }
|
||||
set { SetValue(FontFamilyProperty, value); }
|
||||
}
|
||||
|
||||
public FontStyle FontStyle
|
||||
{
|
||||
get { return (FontStyle)GetValue(FontStyleProperty); }
|
||||
set { SetValue(FontStyleProperty, value); }
|
||||
}
|
||||
|
||||
public FontWeight FontWeight
|
||||
{
|
||||
get { return (FontWeight)GetValue(FontWeightProperty); }
|
||||
set { SetValue(FontWeightProperty, value); }
|
||||
}
|
||||
|
||||
public FontStretch FontStretch
|
||||
{
|
||||
get { return (FontStretch)GetValue(FontStretchProperty); }
|
||||
set { SetValue(FontStretchProperty, value); }
|
||||
}
|
||||
|
||||
public Brush Foreground
|
||||
{
|
||||
get { return (Brush)GetValue(ForegroundProperty); }
|
||||
set { SetValue(ForegroundProperty, value); }
|
||||
}
|
||||
|
||||
public Brush Background
|
||||
{
|
||||
get { return (Brush)GetValue(BackgroundProperty); }
|
||||
set { SetValue(BackgroundProperty, value); }
|
||||
}
|
||||
|
||||
public double OutlineThickness
|
||||
{
|
||||
get { return (double)GetValue(OutlineThicknessProperty); }
|
||||
set { SetValue(OutlineThicknessProperty, value); }
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
return CheckGlyphRun() ? outline.Bounds.Size : new Size();
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext)
|
||||
{
|
||||
if (CheckGlyphRun())
|
||||
{
|
||||
var location = outline.Bounds.Location;
|
||||
drawingContext.PushTransform(new TranslateTransform(-location.X, -location.Y));
|
||||
drawingContext.DrawGeometry(Background, null, outline);
|
||||
drawingContext.DrawGlyphRun(Foreground, glyphRun);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckGlyphRun()
|
||||
{
|
||||
if (glyphRun == null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
|
||||
GlyphTypeface glyphTypeface;
|
||||
|
||||
if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var glyphIndices = new ushort[Text.Length];
|
||||
var advanceWidths = new double[Text.Length];
|
||||
|
||||
for (int i = 0; i < Text.Length; i++)
|
||||
{
|
||||
var glyphIndex = glyphTypeface.CharacterToGlyphMap[Text[i]];
|
||||
glyphIndices[i] = glyphIndex;
|
||||
advanceWidths[i] = glyphTypeface.AdvanceWidths[glyphIndex] * FontSize;
|
||||
}
|
||||
|
||||
glyphRun = new GlyphRun(glyphTypeface, 0, false, FontSize, glyphIndices, new Point(), advanceWidths, null, null, null, null, null, null);
|
||||
|
||||
outline = glyphRun.BuildGeometry().GetWidenedPathGeometry(new Pen(null, OutlineThickness * 2d));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("2.4.1")]
|
||||
[assembly: AssemblyFileVersion("2.4.1")]
|
||||
[assembly: AssemblyVersion("2.4.2")]
|
||||
[assembly: AssemblyFileVersion("2.4.2")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@
|
|||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="OutlinedText.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue