A A
RSS

Silverlight: TemplateBinding Throwing an Error

Fri, Mar 14, 2008

Programming

This drove me crazy for about half an hour… 

I attached this style to a button

<Style x:Key="NavButtonStyle" TargetType="Button">
    <Setter Property="Opacity" Value="0.8"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Grid x:Name="RootElement" 
                     HorizontalAlignment="Stretch" 
                     VerticalAlignment="Stretch">
                    <ContentPresenter 
                        Content="{TemplateBinding Content}"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Everything compiled fine but the page wouldn’t look right and expression blend would not display it correctly and would display the error message:

The member “Content” is not recognized or is not accessible.

I have not idea how I figured out but it turns out that all I had to do is add a TargetType to the ControlTemplate…  I don’t understand why I have to do this since I already set the TargetType on the Style element…  Anyone?

The final style looked like this:

<Style x:Key="NavButtonStyle" TargetType="Button">
    <Setter Property="Opacity" Value="0.8"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid x:Name="RootElement" 
                     HorizontalAlignment="Stretch" 
                     VerticalAlignment="Stretch">
                    <ContentPresenter 
                        Content="{TemplateBinding Content}"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Tags: ,

  • Francesco
    You saved me too!
  • Thx man, you saved my day.
blog comments powered by Disqus
Advertise Here
The Most Intelligent Add-In To Visual Studio Happy fan of

What I'm Doing...

Yonkly Open Source

Sign up for my newsletter




* = required field

powered by MailChimp!

megree Widget

Apparently, I am connected to Obama. Check this out...
My path to Obama

Cyber Identity