WPF 寻找控件模板中的元素
<Window x:Class="Wpf180706.Window10"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window10" Height="300" Width="300">
<Window.Resources>
<ControlTemplate x:Key="temp">
<StackPanel Background="Yellow">
<TextBox Name="txt1" Margin="6"></TextBox>
<TextBox Name="txt2" Margin="6"></TextBox>
<TextBox Name="txt3" Margin="6"></TextBox>
</StackPanel>
</ControlTemplate>
</Window.Resources>
<Grid>
<StackPanel>
<UserControl Name="uc" Template="{StaticResource temp}"></UserControl>
<Button Click="btn_Click">btn</Button>
</StackPanel>
</Grid>
</Window>
using System;
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
{
/// <summary>
/// Interaction logic for Window10.xaml
/// </summary>
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";
}
}
}
WPF 寻找控件模板中的元素的更多相关文章
- WPF 获取控件模板中的控件
DG是控件名称public T GetVisualChild<T>(DependencyObject parent, Func<T, bool> predicate) wher ...
- WPF关于控件 父级控件,子级控件,控件模板中的控件,等之间的相互访问
原文:WPF关于控件 父级控件,子级控件,控件模板中的控件,等之间的相互访问 1,在菜单中访问 弹出菜单的控件 var mi = sender as MenuItem;//菜单条目 MenuItem ...
- WPF默认控件模板的获取和资源词典的使用
一.获取默认的控件模板 WPF修改控件模板是修改外观最方便的方式,但是会出现不知道原来的控件的模板长什么样,或者想用来参考的,下面分享一下获取某控件默认控件模板的方式(已Button为例): 1.创建 ...
- WPF Devexpress 控件库中ChartControl 实现股票分时走势图
概要 从事金融行业开发 ,会接触些图表控件,这里我分享一下自己基于DevExpress.Charts.v16.2开发的股票分时走势图的经验. 附上源码:点击跳转 如果需要讨论,Q群:580749909 ...
- WPF Devexpress控件库中ChartControl--实现不等距x轴
一.概要 解决问题--ChartControl不等距x轴显示 二.CS代码 用过ChartControl的开发者们应该都知道,ChartControl中设置x轴间距间隔都是固定的数值. 比如(间隔10 ...
- WPF标准控件模板查看程序(文件里面)
xaml <Window x:Class="ControlTemplateBrowser.MainWindow" xmlns="http://schemas.mic ...
- WPF Button控件模板
<Window x:Class="ControlTemplateDemo.MainWindow" xmlns="http://schemas.m ...
- 《Programming WPF》翻译 第5章 7.控件模板
原文:<Programming WPF>翻译 第5章 7.控件模板 如果仔细的看我们当前的TTT游戏,会发现Button对象并没有完全为我们工作.哪些TTT面板有内圆角? 图5-14 这里 ...
- WPF数据模板和控件模板
WPF中有控件模板和数据模板,控件模板可以让我们自定义控件的外观,而数据模板定义了数据的显示方式,也就是数据对象的可视结构,但是这里有一个问题需要考虑,数据是如何显示出来的?虽然数据模板定义了数 ...
随机推荐
- windows 空闲超时 非管理员如何破解
windows 空闲超时 非管理员如何破解
- source insight -i failed reason
双击.c调用sourceinsight.exe -i "路径" 如果路径太长就会新开一个窗口,测试相同文件,不同路径现象不同.
- bash - move faster
http://teohm.com/blog/shortcuts-to-move-faster-in-bash-command-line/ Shortcuts to move faster in Bas ...
- 【35.43%】【hdu 4347】The Closest M Points
Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 98304/98304 K (Java/Others) Total Submissio ...
- 【24.91】【Tsinsen 1302】&【BZOJ 2626】JZPFAR
时间限制:5.0s 内存限制:256.0MB 总提交次数:547 AC次数:137 平均分:40.31 将本题分享到: 查看未格式化的试题 提交 试题讨论 试题来 ...
- 【C++竞赛 F】yyy的三角形
时间限制:2s 内存限制:32MB 问题描述 yyy对三角形非常感兴趣,他有n个木棍,他正在用这些木棍组成三角形.这时xxx拿了两根木棍过来,xxx希望yyy能给他一根木棍,使得xxx可以组成一个三角 ...
- c++ 成员函数指针
C++中,成员指针是最为复杂的语法结构.但在事件驱动和多线程应用中被广泛用于调用回叫函数.在多线程应用中,每个线程都通过指向成员函数的指针来调用该函数.在这样的应用中,如果不用成员指针,编程是非常困难 ...
- Android自定义组件系列【1】——自定义View及ViewGroup
View类是ViewGroup的父类,ViewGroup具有View的所有特性,ViewGroup主要用来充当View的容器,将其中的View作为自己孩子,并对其进行管理,当然孩子也可以是ViewGr ...
- Android中动态设置GridView的列数、列宽和行高
在使用GridView时我们知道,列数是可以通过设计时的属性来设置的,列的宽度则是根据列数和GridView的宽度计算出来的.但是有些时候我们想实现列数是动态改变的效果,即列的宽度保持某个值,列的数量 ...
- CoreData使用方法二:NSFetchedResultsController实例操作与解说
学习了NSFetchedResultsController.才深深的体会到coredata的牛逼之处.原来Apple公司弄个新技术.不是平白无故的去弄,会给代码执行到来非常大的优点.coredata不 ...