我有這種自定義控件,但不能從我的主要XAMLWPF自定義用戶控件 - 「會員X無法識別或訪問」
<UserControl x:Class="FireflyMmwDiagnostics.Controls.RegisterTextBox"
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">
<Grid>
<Label Name="LabelRegisterTitle"/>
</Grid>
public partial class RegisterTextBox : UserControl
{
public RegisterTextBox()
{
InitializeComponent();
}
public string RegisterTitle
{
get { return this.LabelRegisterTitle.Content.ToString(); }
set { this.LabelRegisterTitle.Content = value; }
}
訪問它的成員,這是什麼我在主XAML中出現錯誤,指出「成員RegisterTitle無法識別或訪問」:
<Controls:RegisterTextBox RegisterTitle="This Is A Test"/>
我觀看了一些YouTube視頻,這正是他們如何做到的,出於某種原因,這對他們有效。 請諮詢這裏可能是什麼問題。 謝謝!
謝謝!我可能不遵循它,所以它仍然不適合我。我做了正確的更改:'
我剛剛嘗試了您的代碼而未使用「依賴屬性」,並且工作正常。只是爲了檢查,你在用戶控制的最後有' UserControl>'?此外,更改''使用小寫'c',所以'' –
是的,我做最後有' UserControl>',錯過複製/粘貼。但由於某種原因,我仍然無法完成它的工作。順便說一句,爲什麼要將小寫'c'封裝在'FireflyMmwDiagnostics.Controls'命名空間中?它不會以較低的'c'編譯。 – SYB