当前位置:网站首页>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
}
边栏推荐
- ECCV 2022 Oral | 满分论文!视频实例分割新SOTA: IDOL
- 盘点在线帮助中心对企业能够起到的作用
- Reveal how the five operational management level of hundreds of millions of easily flow system
- if/else或switch替换为Enum
- 软件测试技术之如何编写测试用例(3)
- SQL server 实现触发器备份表数据
- NNLM、RNNLM等语言模型 实现 下一单词预测(next-word prediction)
- relocation R_X86_64_PC32 against,/usr/bin/ld: final link failed: Bad value
- 国产虚拟化云宏CNware WinStack安装体验-5 开启集群HA
- 七夕之前,终于整出了带AI的美丽秘笈
猜你喜欢
随机推荐
力扣刷题之爬楼梯(7/30)
利用net-snmp的库实现snmpget,snmpset
Radondb mysql installation problems
Word另存为PDF后无导航栏解决办法
开源生态研究与实践| ChinaOSC
MySQL master-slave, 6 minutes you master!
建模该从哪一步开始?给你分析,给零基础的你一些学习建议
MVC vs MVP
阿洛的反思
net-snmp编译报错:/usr/bin/ld: cannot find crti.o: No such file or directory
Unity gets the actual coordinates of the ui on the screen under the canvas
Postgresql-xl全局快照与GTM代码走读(支线)
JMeter笔记5 |Badboy使用和录制
数据驱动的软件智能化开发| ChinaOSC
1-php学习笔记之数据类型
MySQL基础
基于DMS的数仓智能运维服务,知多少?
线上一次JVM FullGC搞得整晚都没睡,彻底崩溃
ECCV 2022 Oral | 满分论文!视频实例分割新SOTA: IDOL
基于移动GIS的环保生态管理系统









