当前位置:网站首页>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
}
边栏推荐
猜你喜欢
随机推荐
Kettle 读取 Excel 数据输出到 Oracle 详解
力扣刷题之合并两个有序数组
「学习笔记」高斯消元
设备树基本原理与操作方法
149. 直线上最多的点数-并查集做法
图像超分——Real-ESRGAN快速上手
小马智行起诉擎天智卡:索赔6000万 彭军称要斗争到底
Internet Download Manager简介及下载安装包,IDM序列号注册问题解决方法
Radondb mysql installation problems
FreeRTOS中级篇
从文本匹配到语义相关——新闻相似度计算的一般思路
ECCV2022 | 用于视频问题回答的视频图Transformer
力扣解法汇总899-有序队列
ERROR: You don‘t have the SNMP perl module installed.
力扣刷题之数组序号计算(每日一题7/28)
高性能计算软件与开源生态| ChinaOSC
LeetCode 952. 按公因数计算最大组件大小
入门3D建模基础教程详细分解
基于DMS的数仓智能运维服务,知多少?
按需视觉识别:愿景和初步方案









