WatermarkTextBox
Last post 05-21-2008 2:29 PM by Adina. 8 replies.
Sort Posts:
05-12-2008 5:16 AM
WatermarkTextBox

 Hi there...

I'm a noob at silverlight. I'm trying to change the style of a watermarked textbox, but i'm getting the error: "{StaticResource wtbtmplate} is out of range". What's  the problem? What i'm doing wrong?

Page.xaml:

<WatermarkedTextBox Template="{StaticResource wtbTemplate}" Height="96" Width="19" FontFamily="Verdana" FontSize="36" />
 

App.xaml:

Here i have the default style and template for the watermarkedTextBox control (Present in silverlight documentation - March 2008):

<Style TargetType="WatermarkedTextBox" x:Key="wtbTemplate">

            <Setter Property="BorderBrush" Value="#FF000000"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="FontSize" Value="11"/>
            <Setter Property="FontFamily" Value="Trebuchet MS"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="WatermarkedTextBox">
                        <Grid x:Name="RootElement" >

...

</Style>

Hope you can help, and sorry if this a stupid question...

Thanks

darkcrawler

Loading...
Joined on 04-01-2008
Posts 14
05-12-2008 5:33 AM
Re: WatermarkTextBox

Looks like the WatermarkedTextBox class is not mapped to the default xmlns name space. As shown in this MSDN example, you may to do this:

xmlns:local="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Extended"

<Style TargetType="local:WatermarkedTextBox" x:Key="wtbTemplate">

            <Setter Property="BorderBrush" Value="#FF000000"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="FontSize" Value="11"/>
            <Setter Property="FontFamily" Value="Trebuchet MS"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="local:WatermarkedTextBox">
                        <Grid x:Name="RootElement" >

Hope this helps,
Jim (http://jimmangaly.blogspot.com/)

Please MARK the replies as answers if they answered your question

http://www.identitymine.com/

Jim Mangaly

Loading...
Joined on 04-21-2008
Kochi, India
Posts 297
05-12-2008 6:00 AM
Re: WatermarkTextBox

Hi Jim... Thanks for the reply

I had try that... Now I have: 

app.xaml

<Style TargetType="local:WatermarkedTextBox" x:Key="wtbTemplate"
                    xmlns:local="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Extended"
                    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls">

     <Setter Property="BorderBrush" Value="#FF000000"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="FontSize" Value="11"/>
                <Setter Property="FontFamily" Value="Trebuchet MS"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="local:WatermarkedTextBox">

...

</Style>

page.xaml

<WatermarkedTextBox Template="{StaticResource wtbTemplate}" Height="96" Width="19" FontFamily="Verdana" FontSize="11"/>

Same error: "Attribute {StaticResource wtbTemplate} value is out of range."

Any suggestions?
 

darkcrawler

Loading...
Joined on 04-01-2008
Posts 14
05-12-2008 6:33 AM
Re: WatermarkTextBox

The issue turns out to be something very simple :)

You were accessing a style from the template property. Change Template="{StaticResource wtbTemplate}"  to Style="{StaticResource wtbTemplate}"

Hope this helps,
Jim (http://jimmangaly.blogspot.com/)

Please MARK the replies as answers if they answered your question

http://www.identitymine.com/

Jim Mangaly

Loading...
Joined on 04-21-2008
Kochi, India
Posts 297
05-12-2008 6:51 AM
Re: WatermarkTextBox

 I had change that too and nop, didn't help:

<WatermarkedTextBox Style="{StaticResource wtbTemplate}" Width="96" Height="19" Margin="3"></WatermarkedTextBox>

<Style TargetType="local:WatermarkedTextBox" x:Key="wtbTemplate"
    xmlns:local="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Extended"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls">

            <Setter Property="BorderBrush" Value="#FF000000"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="FontSize" Value="11"/>
            <Setter Property="FontFamily" Value="Verdana"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="local:WatermarkedTextBox">

...

</Style> 

? Indifferent 

darkcrawler

Loading...
Joined on 04-01-2008
Posts 14
05-12-2008 7:02 AM
Marked as Answer
Re: WatermarkTextBox

I realized that myself, and was trying to figure out the problem. So it turns out that for the WatermarkedTextBox you cannot set style as of now, but you can set its template explicitly (see Item # 7 in http://blogs.msdn.com/keithjones/archive/2008/03/05/silverlight-2-beta-1-hints.aspx). So you need to change the code to:

<WatermarkedTextBox Template="{StaticResource wtbTemplate}" Width="96" Height="19" Margin="3"></WatermarkedTextBox>

And in App.Resources (remove the style just put the template there):

<ControlTemplate TargetType="local:WatermarkedTextBox" x:Key="wtbTemplate"
    xmlns:local="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Extended"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls">

Hope this helps,
Jim (http://jimmangaly.blogspot.com/)

Please MARK the replies as answers if they answered your question

 

http://www.identitymine.com/

Jim Mangaly

Loading...
Joined on 04-21-2008
Kochi, India
Posts 297
05-12-2008 7:15 AM
Re: WatermarkTextBox

 Ok, that´s the solution!

Thanks Jim, Very grateful!

darkcrawler

Loading...
Joined on 04-01-2008
Posts 14
05-12-2008 7:22 AM
Re: WatermarkTextBox

You need to mark Jim's post as the answer not your thank you note ;) 

Thanks
Yasser Makram
My Blog: http://www.silverlightrecipes.com
Sr. Architect
Santeon Inc. Microsoft Silverlight Partner, Solution Provider

y_makram

Loading...
Joined on 06-07-2007
Cairo, Egypt
Posts 1,138
05-21-2008 2:29 PM
Re: WatermarkTextBox

I have a similar issue and I was trying to follow the steps that you took but obviously I'm missing something. My app.xaml does not compile. Can you show me the code that you have for the watermarkedtextbox in the app.xaml file?

Thanks!

Adina

Loading...
Joined on 05-16-2008
Posts 3