Question

Please pardon me for being a complete newbie, but I'm following a tutorial (Creating a Custom WPF Button Template in XAML), and I'm running into the error:

FormatException was thrown due to document error: Property 'Template' was not found in type 'FrameworkElement'.

It seems that the error stems from the following code in XAML:

 <Setter Property="Template">
     <Setter.Value>
         <ControlTemplate TargetType="Button">
             <Border Name="border"
                BorderThickness="1"
                Padding="4,2"
                BorderBrush="DarkGray"
                CornerRadius="3"
                Background="{TemplateBinding Background}">
                <Grid >
                <ContentPresenter HorizontalAlignment="Center"
                          VerticalAlignment="Center" Name="contentShadow"
                    Style="{StaticResource ShadowStyle}">
                    <ContentPresenter.RenderTransform>
                        <TranslateTransform X="1.0" Y="1.0" />
                    </ContentPresenter.RenderTransform>
                </ContentPresenter>
                <ContentPresenter HorizontalAlignment="Center"
                       VerticalAlignment="Center" Name="content"/>
                </Grid>
        </Border>

I've been looking all over for a solution, but haven't found one...this leads me to believe that I'm either overlooking or overthinking something.

What am I missing? Thank you in advance for any help!

Était-ce utile?

La solution

A FrameworkElement doesn't have a Template property. The Template is usually defined on a Control class. This is because most WPF elements derive from FrameworkElement but they don't all have a Template (StackPanel, for example). Your Setter is probably within a Style (you didn't post that part). Make sure the TargetType of the Style is the correct type (most likely Button).

<Style x:Key="InformButton" TargetType="Button">
    <Setter Property="Template">
         <Setter.Value>
             <ControlTemplate TargetType="Button">
                <Border Name="border"
                etc...
</Style>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top