이 내 XAML 코드 :DataTemplate에서 TextBlock을 클릭하는 방법은 무엇입니까?
Error: The name 'author' does not exist in the current context
그러나 나는이 오류의 원인이나 이유를 이해하지 않습니다
<ListBox ItemsSource="{Binding}" Name="listBox">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel Width="370">
<TextBlock Text="{Binding AuthorName}" x:Name="author" MouseEventLeftDown="click"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
그리고 클릭 처리기
private void click(object sender, RoutedEventArgs e)
{
if(author.Text.Equals("Hi"))
{
// Do Something Special
}
}
오류는 그것은 일어나고있다.
무엇 * 특히 * 당신이 "작동하지 않습니다"에 의해 의미합니까? –