none
Template for textbox behavior

    Question

  • Hi people,

    I'm trying to make a template for a textbox, but it is strange behavior. See this xaml code.

    This code Works:

     <Page.Resources>
            <Style TargetType="TextBox">
                <Setter Property="Height" Value="80" />
                <Setter Property="Foreground" Value="White" />
            </Style>
            <ControlTemplate TargetType="TextBox" x:Key="bordaTexto">
                <Border CornerRadius="5" BorderBrush="#FF2B6789" BorderThickness="4">
                    <TextBox />
                </Border>
            </ControlTemplate>
           
        </Page.Resources>

        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <TextBox Text="teste1" HorizontalAlignment="Left" Margin="23,157,0,0" TextWrapping="Wrap" VerticalAlignment="Top"  Width="349" Template="{StaticResource bordaTexto}"/>
            <TextBox Text="teste2" HorizontalAlignment="Left" Margin="411,157,0,0" TextWrapping="Wrap" VerticalAlignment="Top"  Width="349" Template="{StaticResource bordaTexto}"/>

        </Grid>

    This code doesn't work(difference is element <TextBox /> inside <Border>):

     

     <Page.Resources>
            <Style TargetType="TextBox">
                <Setter Property="Height" Value="80" />
                <Setter Property="Foreground" Value="White" />
            </Style>
            <ControlTemplate TargetType="TextBox" x:Key="bordaTexto">
                <Border CornerRadius="5" BorderBrush="#FF2B6789" BorderThickness="4">

                </Border>
            </ControlTemplate>
           
        </Page.Resources>

        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <TextBox Text="teste1" HorizontalAlignment="Left" Margin="23,157,0,0" TextWrapping="Wrap" VerticalAlignment="Top"  Width="349" Template="{StaticResource bordaTexto}"/>
            <TextBox Text="teste2" HorizontalAlignment="Left" Margin="411,157,0,0" TextWrapping="Wrap" VerticalAlignment="Top"  Width="349" Template="{StaticResource bordaTexto}"/>

        </Grid>

    Thanks...

     
    Tuesday, September 24, 2013 1:03 AM

All replies

  • What is the strange behavior? How does the actual behavior differ from what you expect?

    --Rob

    Tuesday, September 24, 2013 2:26 AM
  • What is the strange behavior? How does the actual behavior differ from what you expect?

    --Rob


    I don't understand because I need add <textBox /> block.
    Tuesday, September 24, 2013 12:43 PM