我需要使用TreeView来制作一个图层面板,我定义了一个节点的样式
<!--主节点样式-->
<Style x:Key="TreeRootStyle" TargetType="TreeViewItem">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Name="imgLayer" HorizontalAlignment="Left" Source="/Images/Sys/layer_layers.png" Width="16" Height="16" />
<TextBlock Name="txtLayer" Margin="5,0,0,0" HorizontalAlignment="Right" Text="Layers" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
绑定样式
<!--图层内容-->
<TreeView Name="treeLayers">
<TreeViewItem Name="rootLayer" Style="{StaticResource TreeRootStyle}" Selected="Layer_Selected" />
</TreeView>
然后我的需求是,当点击一个节点以后需要获取TextBlock的Text内容,我应该怎么做呢?就是在后台的Selected事件中获取内容