我在我想在XAML中设置的代码后面有自定义属性。在XAML中设置UserControl属性
物业:
Public Property WindowName() As String Implements IVendorEntryEditView.WindowName
Get
Return CType(GetValue(WindowNameProperty), Integer)
End Get
Set(ByVal value As String)
SetValue(WindowNameProperty, value)
End Set
End Property
Public Shared ReadOnly WindowNameProperty As DependencyProperty = _
DependencyProperty.Register("WindowName", GetType(String), GetType(VendorEntryEditView), _
New PropertyMetadata(""))
不过,我在我的XAML得到一个Attached property has no setter
消息时,我尝试将其设置:
<UserControl x:Class="VendorEntryEditView"
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"
xmlns:local="clr-namespace:EntryEditUi"
mc:Ignorable="d"
Loaded="VendorEntryEditView_OnLoaded"
local:VendorEntryEditView.WindowName="test"
d:DesignHeight="300" d:DesignWidth="300">
我怎样才能设置该属性在XAML?谢谢!
为什么你需要在XAML中设置它?新的PropertyMetadata(“”)允许您指定该属性的默认值。 这就是你想要达到的目标吗? – Miiite 2013-04-24 16:17:41
我想在XAML中设置它,因为它是我们View Base类的继承属性(我稍后从代码示例中删除)将被重用并需要轻松设置。我认为XAML将是最简单的地方。 – 2013-04-24 16:26:41
尝试从您的XAML中的属性中删除'local:VendorEntryEditView.'前缀。 – 2013-04-24 17:49:20