tags:

views:

624

answers:

1

I'm getting an error for this content template within a style: "Must specify both Property and Value for Setter." Aren't I doing that?

<Style x:Key="LinkButton" TargetType="Button">
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="Button">
            <ContentPresenter/>
        </ControlTemplate>
    </Setter.Value>
</Setter>
<Setter Property="ContentTemplate">
    <Setter.Value>
        <DataTemplate>
            <Label x:Name="ContentRoot">
                <StackPanel Orientation="Horizontal">
                    <Viewbox Width="24" Height="24" VerticalAlignment="Center">
                        <Image x:Name="ButtonImage" Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}, Path=Tag}" />
                    </Viewbox>
                    <TextBlock VerticalAlignment="Center" x:Name="ButtonText" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}, Path=Content}"></TextBlock>
                </StackPanel>
            </Label>
            <DataTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="ButtonText" Property="TextBlock.TextDecorations" Value="Underline"/>
                </Trigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </Setter.Value>
</Setter>

And here is a button that will be using this style:

<Button Name="HelpButton" Style="{StaticResource LinkButton}" Height="30" Content="Help" Tag="Help.png"/>

Thanks!

A: 

Hi Pwninstein

I have loaded this up and have no such problems. The only problem I see is that your button will never have the style applied. This is because if you want the style applied you need to remove the x:Key from the style. Otherwise if you want the style applied only to the HelpButton, the definition should look like this:

<Button Name="HelpButton" Style="{StaticResource LinkButton}" Height="30" Content="Help" Tag="Help.png"/>

But I cannot see the error you are seeing.

Ray Booysen
My bad. I am applying the style to that particular button. Edited. Interesting though...
Pwninstein
Is the error on compile or runtime?
Ray Booysen
It doesn't prevent compilation or running, but it does prevent me from using the designer "ResourceDictionary.xaml cannot be assigned to property 'Source.' The resource dictionary XAML file has errors and cannot be loaded." When I remove that style, the errors go away and I can use the designer.
Pwninstein
Can you post the entire resource dictionary? ;)
Ray Booysen
I'd rather not, as it is quite large (And belongs to my company :) ). If I remove the above style from the resource dictionary, the errors I'm experiencing go away; Are you thinking there's a conflict with another style/template?
Pwninstein
Another thing you can try is remove the Template part of the style. Does it compile now? If it doesn't, try add back the Template and remove the ContentTemplate. Does that compile? If it still doesn't compile, is there a conflict in naming?
Ray Booysen