0
我試圖讓用戶組件可以讓您點擊TextBlock中的一個單詞並對其進行修改。我設法讓單詞可點擊並能夠確定我點擊了哪個單詞。但我也需要知道點擊發生的座標。在TextBlock中點擊超鏈接的獲取點(X,Y)
我的代碼:
<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>
的C#代碼:如何IAM構建的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
}
的內嵌由於點擊參數任何不提供信息,甚至不允許我設置已處理假。這意味着文本塊本身不會觸發Tapped事件。
有沒有辦法,只需要獲取座標?謝謝 !
編輯:我的其他想法。 Iam能夠輕鬆地從Tapped事件中獲取X,Y.那麼是否有可能將透明元素放在textblock前面作爲不可見的畫布,並處理事件並將其傳遞給下面的元素?