当前位置:网站首页>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
}
边栏推荐
猜你喜欢
随机推荐
系统太多,多账号互通如何实现?
Unity gets the actual coordinates of the ui on the screen under the canvas
开源生态研究与实践| ChinaOSC
LeetCode 622. Designing Circular Queues
Climbing Stairs (7/30)
The ecological environmental protection management system based on mobile GIS
「游戏建模干货」建模大师几步操作,学习经典,赶紧脑补一下吧
线上一次JVM FullGC搞得整晚都没睡,彻底崩溃
力扣刷题之爬楼梯(7/30)
余弦距离介绍
X86 function call model analysis
手把手教你定位线上MySQL慢查询问题,包教包会
【leetcode】剑指 Offer II 007. 数组中和为 0 的三个数(双指针)
Reveal how the five operational management level of hundreds of millions of easily flow system
dpkg强制安装软件
基于DMS的数仓智能运维服务,知多少?
net-snmp编译报错:/usr/bin/ld: cannot find crti.o: No such file or directory
力扣刷题之分数加减运算(每日一题7/27)
Internet Download Manager简介及下载安装包,IDM序列号注册问题解决方法
docker mysql 容器中执行mysql脚本文件并解决乱码