我在stackpanel内有边框(按钮):
<StackPanel>
<Border MouseLeftButtonUp="selectStudent" x:Name="button_0">
<TextBlock >Anna</TextBlock>
</Border>
<Border MouseLeftButtonUp="selectStudent" x:Name="button_1">
<TextBlock>Bart</TextBlock>
</Border>
</StackPanel>
如果按下x:Name="button_0"
,我想将Visibility
x:Name="titel_0"
更改为Visible
,所有其他标题保持Collapsed
<TextBlock Visibility="Collapsed" x:Name="titel_0">Anna</TextBlock>
<TextBlock Visibility="Collapsed" x:Name="titel_1">Bart</TextBlock>
我将边框和标题放在一个数组中:
var buttons = new Array(2);
for (var i = 0; i < 2; i++) {
buttons[i] = schermPage.content.findName('button_' + i);
}
var titels = new Array(2);
for (var i = 0; i < 2; i++) {
titels[i] = schermPage.content.findName('titel_' + i);
}
如何开始编写selectStudent
函数?
我试过
function selectStudent() {
if (buttons[0]) {
titels[0].Visibility = 'Visible'
}
}
但是如果我按下另一个边框,它仍会显示Anna
答案 0 :(得分:0)
这是您的selectStudent函数的样子
void selectStudent(object sender, MouseButtonEventArgs e)
{
string controlName = ((Border)sender).Name;
//Write your if statement or switch case based on the controlName.
}