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">
TestControl.xaml.cs
using System.Windows.Controls;
namespace MyProject.Controls
{
public partial class TestControl : UserControl
{
public string TestMe { get; set; }
public TestControl()
{
InitializeComponent();
}
}
}
然后,在我的MainWindow.xaml文件中,我尝试包含这个:
<controls:TestControl TestMe="asdf" />
然而,即使Visual Studio自动完成了TestMe属性,我仍然看到有波浪线的下划线,上面写着“成员“Test Me”未被识别或不可访问”,如下图所示。
我敢肯定我以前在其他项目中做过类似的事情。我该如何像这样通过XAML访问(即设置)公共属性?