当前位置:网站首页>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
}
边栏推荐
猜你喜欢
随机推荐
Calculation of the array serial number of Likou brush questions (one question per day 7/28)
阿洛的反思
FreeRTOS中级篇
阿里巴巴政委体系-第八章、阿里政委工作方法论
机器学习中专业术语的个人理解与总结(纯小白)
Force is brushed buckle problem for the sum of two Numbers
pg_memory_barrier_impl in Postgresql and C's volatile
X86 function call model analysis
阿里二面:多线程间的通信方式有几种?举例说明
LeetCode 952. 按公因数计算最大组件大小
【leetcode】剑指 Offer II 009. 乘积小于 K 的子数组(滑动窗口、双指针)
net-snmp编译报错:/usr/bin/ld: cannot find crti.o: No such file or directory
Postgresql快照优化Globalvis新体系分析(性能大幅增强)
力扣刷题之移动零
622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)
LeetCode 952. Calculate Maximum Component Size by Common Factor
从腾讯阿里等大厂出来创业搞 Web3、元宇宙的人在搞什么
FreeRTOS Intermediate
LeetCode 622. 设计循环队列
单调栈及其应用