通过 Javascript 访问 Xaml 元素属性
(再次,一个 Xaml 问题。不幸的是,我们的老师不是很有用...)
我在 xaml 文件中有以下元素:
<TextBlock Style="{StaticResource TitleText}" x:Name="InformationGainTextBlock" />
<TextBlock Style="{StaticResource TitleText}" x:Name="NGramTextBlock" />
<TextBlock Style="{StaticResource TitleText}" x:Name="PositionTextBlock" />
我还有 200 个行元素,包含数据,如下所示:
<Line Name="Data0" Stroke="Maroon" StrokeThickness="1" X1="154" Y1="123" X2="154" Y2="549" MouseEnter="onMouseEnter" MouseLeave="onMouseLeave" Tag="0.0427409|e l i j k|1" />
现在,想法是,在onMouseEnter 函数(在 JavaScript 文件中),我从“Tag”属性中提取数据并将其作为文本放入文本块中。在此示例中:
0.0427409|e l i j k|1
因此,我必须将“0.0427409”放入 InformationGainTextBlock,将“elij k”放入 NGramTextBlock,将“1”放入 PositionTextBlock。我还必须更改线条颜色。
我怎样才能做到这一点?我认为我的伪代码是正确的,但不是确切的实现:
onMouseEnter(sender, args) {
var data = sender.getAttribute("Tag").Text;
var array[] = data.Split("|");
sender.getElementByName("InformationGainTextBlock").text = array[0];
sender.getElementByName("NGramTextBlock").text = array[1];
sender.getElementByName("PositionTextBlock").text = array[2];
sender.getAttribute("Stroke").text = "Red";
}
onMouseLeave 事件重置一切。
(Again, a Xaml question. Our teacher isn't very useful unfortunately...)
I have following elements in a xaml file:
<TextBlock Style="{StaticResource TitleText}" x:Name="InformationGainTextBlock" />
<TextBlock Style="{StaticResource TitleText}" x:Name="NGramTextBlock" />
<TextBlock Style="{StaticResource TitleText}" x:Name="PositionTextBlock" />
I also have 200 line elements, containing data, like this:
<Line Name="Data0" Stroke="Maroon" StrokeThickness="1" X1="154" Y1="123" X2="154" Y2="549" MouseEnter="onMouseEnter" MouseLeave="onMouseLeave" Tag="0.0427409|e l i j k|1" />
Now, the idea is that, in the onMouseEnter function (in a javascript file), I extract data from the "Tag" attribute and put it as text in the textblocks. In this example:
0.0427409|e l i j k|1
So, I have to put '0.0427409' in the InformationGainTextBlock, 'e l i j k' in the NGramTextBlock and '1' in the PositionTextBlock. I also have to change the line colour.
How am I able to do this? I think I've got the pseudocode about right, but not the exact implementation:
onMouseEnter(sender, args) {
var data = sender.getAttribute("Tag").Text;
var array[] = data.Split("|");
sender.getElementByName("InformationGainTextBlock").text = array[0];
sender.getElementByName("NGramTextBlock").text = array[1];
sender.getElementByName("PositionTextBlock").text = array[2];
sender.getAttribute("Stroke").text = "Red";
}
The onMouseLeave event resets everything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西应该有效:
你所拥有的非常接近:)
Something like this should work:
What you had was very close :)