SL2.0 - Can't use a TextBox after having customized it.
Last post 03-27-2008 2:14 PM by Danial Zaki. 1 replies.
Sort Posts:
03-27-2008 1:03 PM
SL2.0 - Can't use a TextBox after having customized it.

--- This post has already been posted in the "Design" forum... but it seems it was nor the right place - Sorry posting it 2 times--- 

Hi all,
I'm working on Customizing Silverlight Controls. I would like to Set all my TextBox with :

  • a custom backgroud
  • a RadiusX="3" RadiusY="3"
But it seems we can't set a specific radius to a TextBox.
So I've done the following ControlTemplate :

<Style TargetType="TextBox" x:Key="_STYL_TextBox">
  <Setter Property="Template">
   
<Setter.Value>
     
<ControlTemplate TargetType="TextBox">
       
<Grid>
          
<Rectangle Width="90" Height="20" Stroke="#FFFFFFFF" StrokeThickness="1" RadiusX="3" RadiusY="3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,0,0,0">
                
<Rectangle.Fill>
                   
<LinearGradientBrush EndPoint="0.504,0.483" StartPoint="0.504,-0.4">
                   
<GradientStop Color="#FFB4DDFF" Offset="0.524"/>
                   
<GradientStop Color="#FFFCFCFC" Offset="1"/>
                   
<GradientStop Color="#FFDDEEFD" Offset="0.688"/>
                
</LinearGradientBrush>
             
</Rectangle.Fill>
         
</Rectangle>
        
<TextBox Text="{TemplateBinding Text}" Width="Auto" Height="Auto" Margin="0,0,0,0" BorderThickness="0,0,0,0" Background="#00FFFFFF" FontSize="12"/>
     
</Grid>
    </ControlTemplate>
  </Setter.Value>
 </Setter>
</Style>

But we I want to apply it to my text box,

<TextBox x:Name="_TBX_Test" Style="{StaticResource _STYL_TextBox}" Text="Eric" Canvas.Top="10" Canvas.Left="10" />

I can't type-in anything in my textbox...
 

It seems I could do something setting completly the Template... but I don't want to redefine completly a tesbox for a simple border...

thanks for your help,

Eric.

eric.trecanne

Joined on 03-26-2008
Paris
Posts 12
03-27-2008 2:14 PM
Marked as Answer
Re: SL2.0 - Can't use a TextBox after having customized it.

Why do you use another TextBox in your template?

 The Template contract for TextBox is to have a Border Element with name "ELEMENT_content" like this

<ControlTemplate>

         <Border x:Name="ELEMENT_Content"

                        BorderThickness="{TemplateBinding BorderThickness}"

                        BorderBrush="{TemplateBinding BorderBrush}"

                        Padding="{TemplateBinding Padding}"

                        Background="{TemplateBinding Background}"

                        />

</ControlTemplate>

This template will render the TextBox with the default view. You can for sure customize any of these properties, like the background to be customized as you want. You can contain this Broder inside a Rectangle with Radious, etc..

Thanks

Danial Zaki

Danial Zaki

Joined on 03-10-2008
Posts 30