WPF 寻找控件模板中的元素
2021-05-29 22:18
标签:windows microsoft btn round ext private using inpu send using System; WPF 寻找控件模板中的元素 标签:windows microsoft btn round ext private using inpu send 原文地址:https://www.cnblogs.com/Jeely/p/11076266.html
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window10" Height="300" Width="300">
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Wpf180706
{
///
/// Interaction logic for Window10.xaml
///
public partial class Window10 : Window
{
public Window10()
{
InitializeComponent();
}
private void btn_Click(object sender, RoutedEventArgs e)
{
TextBox txt = (TextBox)this.uc.Template.FindName("txt1",this.uc);
txt.Text = "Hello";
StackPanel sp = txt.Parent as StackPanel;
((TextBox)sp.Children[1]).Text = "Hello2";
((TextBox)sp.Children[2]).Text = "Hello3";
}
}
}