我在Code Behind中有自定义属性,我想在XAML中设置。
属性:
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中设置该属性?谢谢!
答案 0 :(得分:1)
也许只是尝试(使用UserControl
的地方):
<local:VendorEntryEditView WindowName="Test Value" />
或如果您必须在UserControl
本身的xaml中指定此值,请通过Style
VendorEntryEditView.xaml
进行分配
<UserControl.Style>
<Style>
<Setter Property="local:VendorEntryEditView.WindowName"
Value="Blah Name" />
</Style>
</UserControl.Style>