当前位置:网站首页>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
}
边栏推荐
- MySQL基础
- Unity gets the actual coordinates of the ui on the screen under the canvas
- 622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)
- pytorch框架实现老照片修复功能详细演示(GPU版)
- 力扣解法汇总899-有序队列
- redis常用命令,HSET,XADD,XREAD,DEL等
- Postgresql-xl global snapshot and GTM code walking (branch line)
- 国产虚拟化云宏CNware WinStack安装体验-5 开启集群HA
- 「游戏建模干货」建模大师几步操作,学习经典,赶紧脑补一下吧
- flex布局
猜你喜欢
虚拟机vmware设置nat模式上网
告诉你0基础怎么学好游戏建模?
Introduction to Cosine Distance
MySQL 主从,6 分钟带你掌握!
Benchmarking Lane-changing Decision-making for Deep Reinforcement Learning
高效目标检测:动态候选较大程度提升检测精度(附论文下载)
按需视觉识别:愿景和初步方案
【夜莺监控方案】08-监控msyql集群(prometheuse+n9e+mysqld_exporter)
MySQL基础
Network protocol-TCP, UDP difference and TCP three-way handshake, four wave
随机推荐
阿里巴巴政委体系-第五章、阿里政委体系建设
CentOS 7 安装mysql
node版本切换工具NVM以及npm源管理器nrm
京东云发布新一代分布式数据库StarDB 5.0
力扣刷题之分数加减运算(每日一题7/27)
ADS 2023 下载链接
Shell编程之循环语句
怎么将自己新文章自动推送给自己的粉丝(巨简单,学不会来打我)
2022 CCF中国开源大会会议通知(第三轮)
Compose原理-compose中是如何实现事件分法的
SQL server 实现触发器备份表数据
tensorflow-gpu2.4.1安装配置详细步骤
力扣刷题之爬楼梯(7/30)
LeetCode 952. Calculate Maximum Component Size by Common Factor
JS 内置构造函数 扩展 prototype 继承 借用构造函数 组合式 原型式creat 寄生式 寄生组合式 call apply instanceof
基础软件与开发语言开源论坛| ChinaOSC
Unity gets the actual coordinates of the ui on the screen under the canvas
LeetCode 622. 设计循环队列
【统计机器学习】线性回归模型
MySQL 主从,6 分钟带你掌握!