Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FrameworkElement.Name problem

I am attempting to set the Name property of a Page in the constructor:

public partial class PageListView : Page
{
    public PageListView(string title)
    {
        InitializeComponent();
        Name = title;
    }
}

However, I often get the following error message.

'x' is not a valid value for property 'Name'.

Where x seems to be almost anything, drilling down into the exception details doesn't seem to provide any useful information (e.g. the InnerException is null.)

Does anyone know what is happening here?

like image 719
ocodo Avatar asked Mar 24 '11 00:03

ocodo


1 Answers

The Name property generally follows the rules of C#/VB.NET identifiers (i.e. fields). Based on the documentation:

The string values used for Name have some restrictions, as imposed by the underlying x:Name Directive defined by the XAML specification. Most notably, a Name must start with a letter or the underscore character (_), and must contain only letters, digits, or underscores.

Based on the parameter you are passing (i.e. title), it seems like you may violate that. But you'd have to give some specific examples to be sure.

like image 79
CodeNaked Avatar answered Oct 17 '22 04:10

CodeNaked