相关疑难解决方法(0)

为什么我在WPF用户控件上看到"成员无法识别或无法访问"错误?

我有一个自定义用户控件,其中包含我希望能够在XAML中设置的公共属性.它在下面.

TestControl.xaml

<UserControl x:Class="Scale.Controls.TestControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
Run Code Online (Sandbox Code Playgroud)

TestControl.xaml.cs

using System.Windows.Controls;

namespace MyProject.Controls
{
    public partial class TestControl : UserControl
    {
        public string TestMe { get; set; }
        public TestControl()
        {
            InitializeComponent();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后,在我的MainWindow.xaml文件中,我尝试包含这个:

<controls:TestControl TestMe="asdf" />
Run Code Online (Sandbox Code Playgroud)

但是,即使Visual Studio自动填充了TestMe属性,我也会看到带有波浪线下划线的内容,表示"成员"测试我"无法识别或无法访问",如下所示.

成员

我可以发誓我之前在其他项目中做过类似的事情.如何通过XAML访问(即设置)公共属性?

c# wpf xaml

18
推荐指数
4
解决办法
3万
查看次数

标签 统计

c# ×1

wpf ×1

xaml ×1