Reputation: 192
I'm trying to make usercomponent which will let you click onto a word inside TextBlock and modify it. I managed to make the words clickable and be able to determine which word I've clicked. But I also need to know the coordinates where the click happened.
My code:
<UserControl
x:Class="wordedit.EditableTextBlock"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:wordedit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid Name="grid">
<TextBlock Margin="0" Padding="0" LineStackingStrategy="BaselineToBaseline" TextLineBounds="Full" TextWrapping="WrapWholeWords" Name="textBlock">
</TextBlock>
</Grid>
</UserControl>
the C# Code: how iam constructing the Inline of TextBlock
Run r = new Run();
r.Text = words[i];
Hyperlink l = new Hyperlink();
l.Click += L_Click;
l.Inlines.Add(r);
textBlock.Inlines.Add(l);
private void L_Click(Hyperlink sender, HyperlinkClickEventArgs args)
{ // doing some user response here
}
Since the Click arguments provide no information whatsoever and doesn't even allow me to set Handled to false. That means the textblock itself wont fire the Tapped event.
Is there a way, to simply get the coordinates ? Thank you !
EDIT: My other thoughts. Iam able to easily get X,Y from Tapped event. So is it possible to put transparent element in front of textblock to act as invisible canvas and handle the event and pass it thru to element underneath?
Upvotes: 0
Views: 60
Reputation: 192
Okay, I think I solved it by using PointerReleased event on the grid. Somehow this event works.
private void Grid_PointerReleased(object sender, PointerRoutedEventArgs e)
{
var point = e.GetCurrentPoint(grid);
}
Upvotes: 0