我在我想在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