(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;
v开发者_开发知识库ar 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.
Something like this should work:
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];
}
What you had was very close :)
精彩评论