Pergunta

Please forgive the obtuse title, not sure how best to phrase my problem...

I have written a custom control "CustomControl" in project Foo. It has a dependency property "Title" which is a string:

public static readonly DependencyProperty TitleProperty =
    DependencyProperty.Register(
        "Title",
         typeof(string),
         typeof(CustomControl),
         PropertyMetadata.Create("Default Title")
    );
public string Title
{
    get { return (string)GetValue(TitleProperty); }
    set { SetValue(TitleProperty, value); }
}

In my Generic.xaml file, I am trying to set the value of "Title" with a Setter node:

<Style TargetType="local:CustomControl">

    <!-- Setter for Template property -->

    <Setter Property="Title" Value="Any String" />
</Style>

The app chokes as soon as it tries to render the control, saying it cannot find the "Title" property in my control:

An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in Foo.exe but was not handled in user code

WinRT information: The property 'Title' was not found in type 'Foo.Controls.CustomControl'. [Line: X Position: Y]

Additional information: Unspecified error

Am I doing something wrong here? Is this not allowed? When I break in the debugger I can see the Title property on the object, so I'm pretty perplexed.

Foi útil?

Solução

I feel silly and it may be best that this question just be deleted, because after hours of hair pulling I solved it 10 seconds after posting the question.

The problem was in my DependencyProperty.Register call. I had the owner type (third argument) referencing a class with a very similar name, and not actually the owning class. Oops. :(

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top