Search code examples
wpfuser-controlscustom-controlstemplatebinding

TemplateBinding error


I develop a custom control which has a dependency property

public static readonly DependencyProperty StateBorderBrushProperty =
        DependencyProperty.Register("StateBorderBrush", typeof(Brush), typeof(SmartCanvas),
        new FrameworkPropertyMetadata(Brushes.Transparent,
            FrameworkPropertyMetadataOptions.None));

The problem arise when I try to set ControlTemplate of my control from outside xaml like

<ControlTemplate TargetType="controls:SmartPrimitive">
                    <Grid>
                        <ContentPresenter/>
                        <Border BorderBrush="{TemplateBinding StateBorderBrush}" BorderThickness="2"/>
                    </Grid>
                </ControlTemplate>

It sounds like "XamlParseException: The given key was not present in the dictionary" in the string with TemplateBinding above. What could be wrong?


Solution

  • I've just misspelled with the type of the DependencyProperty owner. It should be SmartPrimitive, not SmartCanvas. But... WPF exception might be more informative.