如何在WPF中以编程方式删除TextBoxTemplate? [英] how to remove TextBoxTemplate programmatically in WPF?

查看:98
本文介绍了如何在WPF中以编程方式删除TextBoxTemplate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的xmal文件是

hi all,
my xmal file is

<TextBox  Name="txtNewField"  Grid.Column="0" Width="150" Height="30" Margin="0,0,0,0" >
                <TextBox.Template>
                    <ControlTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions></Grid.ColumnDefinitions>
                            <TextBox Grid.Column="0"></TextBox>
                            <Button HorizontalAlignment="Right" Name="btnClose"   Width="10" Click="imgRemove_Click" Height="10" Grid.Column="1">
                                
                            </Button>
                        </Grid>
                    </ControlTemplate>
                </TextBox.Template>
            </TextBox>



现在我想以编程方式删除Textbox.Template

怎么做?

谢谢所有。


now i want to programmatically remove Textbox.Template
how to do this?
thanks all.

推荐答案

嗨所有

解决了

如果我们设置TextBox.Template = null然后TextBox内容将被删除

但我们可以定义其他模板和

以编程方式设置为TextBox.Template

例如:

hi all
solved
if we set TextBox.Template=null then TextBox Content will be removed
but we can define other template and
set programically it to TextBox.Template
for example:
<controltemplate x:key="NewTemp" targettype="{x:Type TextBox}" xmlns:x="#unknown">
               <grid>
                   <textbox grid.column="0" />
               </grid>
           </controltemplate>



和C#代码:


and C# code:

this.TextBox1.Template = FindResource("NewTemp") as ControlTemplate;



谢谢。


thanks.


这篇关于如何在WPF中以编程方式删除TextBoxTemplate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆