当前位置:网站首页>Use ControlTemplate or Style from resource file in WPF .cs and find the control
Use ControlTemplate or Style from resource file in WPF .cs and find the control
2022-08-03 19:42:00 【Xiao Caiyuan who loves programming】
一、Generic.xaml中:
<ControlTemplate x:Key="ucQuitFeeCT" TargetType="{x:Type localControls:ucQuitFee}">
<Grid Grid.Row="1">
<TabControl Grid.Row="0" x:Name="neuTabControl1" Style="{DynamicResource tabControlStyle}">
<TabItem Header="退费(F2)" IsSelected="True" x:Name="tpQuit" Style="{DynamicResource tabItemStyle}">
<GroupBox Header="基本信息">
<DockPanel>
<TextBlock Width="55" Margin="5 0" VerticalAlignment="Center" >发票号:</TextBlock>
<!--For example look for this control-->
<TextBox x:Name="tbInvoiceNO" Width="132" VerticalAlignment="Center"></TextBox>
</DockPanel>
</GroupBox>
</TabItem>
</TabControl>
</Grid>
</ControlTemplate>
二、.cs中
#region 声明控件
protected TextBox tbInvoiceNO = new TextBox();
#endregion
ControlTemplate thisControlTemplate = null;
public void SetControlTemplate()
{
ResourceDictionary resourceDictionary = new ResourceDictionary();
resourceDictionary.Source = new Uri("/程序集;component/Themes/Generic.xaml", UriKind.RelativeOrAbsolute);
this.Resources.MergedDictionaries.Add(resourceDictionary);
thisControlTemplate = (ControlTemplate)this.Resources["ucQuitFeeCT"];
this.Template = thisControlTemplate;
}
//得到控件
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
#region 控件赋值
tbInvoiceNO = (TextBox)thisControlTemplate.FindName("tbInvoiceNO", this);
#endregion
#region Bind control events
#endregion
}
边栏推荐
- Postgresql源码(64)查询执行——子模块Executor(2)执行前的数据结构和执行过程
- Power button brush the topic of merging two orderly array
- Brush the topic of mobile zero power button
- 设备树基本原理与操作方法
- 软件测试技术之如何编写测试用例(3)
- JS 内置构造函数 扩展 prototype 继承 借用构造函数 组合式 原型式creat 寄生式 寄生组合式 call apply instanceof
- 深入理解JVM-内存结构
- JMeter笔记5 |Badboy使用和录制
- 「学习笔记」高斯消元
- 告诉你0基础怎么学好游戏建模?
猜你喜欢
随机推荐
1-php学习笔记之数据类型
简易电子琴设计(c语言)
宁德时代2号人物黄世霖辞任副董事长:身价1370亿
【leetcode】剑指 Offer II 009. 乘积小于 K 的子数组(滑动窗口、双指针)
WPF .cs中使用资源文件中的ControlTemplate或Style并找到控件
从文本匹配到语义相关——新闻相似度计算的一般思路
线上一次JVM FullGC搞得整晚都没睡,彻底崩溃
dpkg强制安装软件
FreeRTOS中级篇
net-snmp编译报错:/usr/bin/ld: cannot find crti.o: No such file or directory
Handler source code analysis
MySQL基础
MVC vs MVP
Postgresql source code (64) Query execution - data structure and execution process before submodule Executor (2) execution
CS kill-free pose
云图说丨初识华为云微服务引擎CSE
设备树基本原理与操作方法
「游戏建模干货」建模大师几步操作,学习经典,赶紧脑补一下吧
国产虚拟化云宏CNware WinStack安装体验-5 开启集群HA
ERROR: You don‘t have the SNMP perl module installed.