wpf 查找Control Template内部控件


        
            
                
                
                
                    
                        
                            
                                
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            Button b = (Button)sender;
            int index = DataGrid1.SelectedIndex;
            object ww = DataGrid1.SelectedItem;

            StackPanel sp = b.Parent as StackPanel;
            Label tb = sp.FindName("Label1") as Label;


        }

                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp5"
            xmlns:arr="clr-namespace:System.Collections;assembly=mscorlib"
            xmlns:sys="clr-namespace:System;assembly=mscorlib"
            mc:Ignorable="d"
            Title="MainWindow" Height="450" Width="800">
       
           
               
                   
                   
                   
               

               
           

       

     
     
       
           
           

WPF