gpt4 book ai didi

javascript - 通过 Javascript 访问 Xaml 元素属性

转载 作者:行者123 更新时间:2023-11-30 18:44:14 24 4
gpt4 key购买 nike

(同样,一个 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”属性中提取数据并将其作为文本放入文本 block 中。在这个例子中:

0.0427409|e l i j k|1

因此,我必须在 InformationGainTextBlock 中放置“0.0427409”,在 NGramTextBlock 中放置“e l i j k”,在 PositionTextBlock 中放置“1”。我还必须更改线条颜色。

我怎样才能做到这一点?我想我得到的伪代码是正确的,但不是确切的实现:

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 事件重置一切。

最佳答案

像这样的东西应该可以工作:

function onMouseEnter(sender, mouseEventArgs) {
var text = sender["Tag"];
var array = new Array();
array = text.split("|");
sender["Stroke"] = "Red";
sender.findName("InformationGainTextBlock").text = array[0];
sender.findName("NGramTextBlock").text = array[1];
sender.findName("PositionTextBlock").text = array[2];
}

你所拥有的非常接近:)

关于javascript - 通过 Javascript 访问 Xaml 元素属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5922800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com