2011-05-07 133 views
1

屬性(同樣,在XAML問題我們的老師是不是很有用......不幸。)訪問的XAML元素通過JavaScript

我有以下了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文件),I從「變量」屬性提取數據,並把它作爲TE xt在文本塊中。在這個例子中:

0.0427409|e l i j k|1 

所以,我必須把 '0.0427409' 在InformationGainTextBlock在NGramTextBlock, 'E的L- I J K' 和 '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事件重置所有內容。

回答

2

像這樣的東西應該工作:

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]; 
} 

什麼你有非常密切的:)

+0

感謝隊友,認爲這樣做是:d – Matthias 2011-05-07 18:35:49