FrameworkElement.Name 问题 [英] FrameworkElement.Name problem

查看:70
本文介绍了FrameworkElement.Name 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在构造函数中设置 Page 的 Name 属性:

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'.

x 似乎几乎是任何东西的地方,深入到异常细节似乎没有提供任何有用的信息(例如 InnerException 为空.)

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?

推荐答案

Name 属性通常遵循 C#/VB.NET 标识符(即字段)的规则.基于文档:

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

用于 Name 的字符串值有一些限制,如XAML 规范定义的基础 x:Name 指令.最值得注意的是,名称必须以字母或下划线字符开头(_),并且只能包含字母、数字或下划线.

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.

这篇关于FrameworkElement.Name 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆