当前位置:网站首页>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
}
边栏推荐
猜你喜欢
随机推荐
622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)
2022年最新的Android面试大厂必考174题(附带详细答案)
Postgresql源码(65)新快照体系Globalvis工作原理分析
Handler 源码解析
利用net-snmp的库实现snmpget,snmpset
小马智行起诉擎天智卡:索赔6000万 彭军称要斗争到底
力扣刷题之移动零
从文本匹配到语义相关——新闻相似度计算的一般思路
友宏医疗与Actxa签署Pre-M Diabetes TM 战略合作协议
【木马免杀】
LeetCode 952. Calculate Maximum Component Size by Common Factor
ScrollView嵌套RV,滑动有阻力不顺滑怎么办?
开源生态研究与实践| ChinaOSC
Solution for no navigation bar after Word is saved as PDF
The ecological environmental protection management system based on mobile GIS
epoll + 线程池 + 前后置服务器分离
NNLM、RNNLM等语言模型 实现 下一单词预测(next-word prediction)
relocation R_X86_64_PC32 against,/usr/bin/ld: final link failed: Bad value
危化企业双重预防机制数字化建设进入全面实施阶段
花 30 美金请 AI 画家弄了个 logo,网友:画得非常好,下次别画了!









