当前位置:网站首页>WPF .cs中使用资源文件中的ControlTemplate或Style并找到控件
WPF .cs中使用资源文件中的ControlTemplate或Style并找到控件
2022-08-03 19:36:00 【爱编程的小菜媛】
一、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>
<!--举例寻找这个控件-->
<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 绑定控件事件
#endregion
}
边栏推荐
猜你喜欢
随机推荐
盲僧发现了华点——教你如何使用API接口获取数据
The ecological environmental protection management system based on mobile GIS
NNLM、RNNLM等语言模型 实现 下一单词预测(next-word prediction)
开源教育论坛| ChinaOSC
List类的超详细解析!(超2w+字)
net-snmp编译报错:/usr/bin/ld: cannot find crti.o: No such file or directory
Protobuf Grpc使用异常 类型有未导出的方法,并且是在不同的软件包中定义
ERROR: You don‘t have the SNMP perl module installed.
【微信小程序】NFC 标签打开小程序
FreeRTOS中级篇
基于DMS的数仓智能运维服务,知多少?
盘点在线帮助中心对企业能够起到的作用
The effective square of the test (one question of the day 7/29)
虚拟机vmware设置nat模式上网
按需视觉识别:愿景和初步方案
【夜莺监控方案】08-监控msyql集群(prometheuse+n9e+mysqld_exporter)
Postgresql snapshot optimization Globalvis new system analysis (performance greatly enhanced)
LeetCode 622. Designing Circular Queues
基于移动GIS的环保生态管理系统
力扣刷题之移动零