Click here to Skip to main content
15,889,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
my xmal file is
XML
<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>

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

1 solution

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:
XML
<controltemplate x:key="NewTemp" targettype="{x:Type TextBox}" xmlns:x="#unknown">
               <grid>
                   <textbox grid.column="0" />
               </grid>
           </controltemplate>

and C# code:
C#
this.TextBox1.Template = FindResource("NewTemp") as ControlTemplate;

thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900