Created
July 28, 2010 17:10
-
-
Save mwinckler/495341 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MapEditMode _mapEditMode = MapEditMode.normal; | |
private void wpfMap1_MapClick(object sender, ThinkGeo.MapSuite.WpfDesktopEdition.MapClickWpfMapEventArgs e) { | |
if (_mapEditMode == MapEditMode.add_text) { | |
_mapEditMode = MapEditMode.adding_text; | |
wpfMap1.Cursor = Cursors.Arrow; | |
var canvas = new Canvas(); | |
TextEditor editor = null; | |
editor = new TextEditor(str => { | |
//TODO: save string to map | |
canvas.Children.Remove(editor); | |
mapGrid.Children.Remove(canvas); | |
_mapEditMode = MapEditMode.normal; | |
}); | |
// Set margin to the location of the mouse click. | |
editor.Margin = new Thickness(e.ScreenX, e.ScreenY, 0, 0); | |
canvas.Children.Add(editor); | |
mapGrid.Children.Add(canvas); | |
return; | |
} | |
} | |
private void MenuItemAddText_Click(object sender, RoutedEventArgs e) { | |
// Set special cursor mode. | |
if (_mapEditMode != MapEditMode.add_text) { | |
_mapEditMode = MapEditMode.add_text; | |
wpfMap1.Cursor = Cursors.IBeam; | |
} else { | |
_mapEditMode = MapEditMode.normal; | |
wpfMap1.Cursor = Cursors.Arrow; | |
} | |
} | |
private enum MapEditMode { | |
normal, | |
add_text, | |
adding_text | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="LabelingExample.UserControls.TextEditor" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
Width="300" | |
Height="30"> | |
<TextBox Name="txtEditor" BorderThickness="1"> | |
<TextBox.Background> | |
<SolidColorBrush Color="White" Opacity="0.2" /> | |
</TextBox.Background> | |
</TextBox> | |
</UserControl> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
namespace LabelingExample.UserControls { | |
/// <summary> | |
/// Interaction logic for TextEditor.xaml | |
/// </summary> | |
public partial class TextEditor : UserControl { | |
public TextEditor(Action<string> saveCallback) { | |
InitializeComponent(); | |
this.Loaded += (sender, e) => { | |
Action saveText = () => { | |
if (null != saveCallback) { | |
saveCallback(txtEditor.Text); | |
} | |
}; | |
txtEditor.Focus(); | |
txtEditor.LostFocus += (sndr, ev) => saveText(); | |
txtEditor.KeyUp += (sndr, ev) => { | |
if (ev.Key == Key.Enter) { | |
if (Keyboard.Modifiers == ModifierKeys.Control) { | |
txtEditor.Text += Environment.NewLine; | |
txtEditor.Select(txtEditor.Text.Length, 0); | |
} else { | |
saveText(); | |
} | |
} | |
}; | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment