[英]Setting a UserControl property in XAML
我想在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(""))
但是,当我尝试设置Attached property has no setter
时,我的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中设置该属性? 谢谢!
也许只是尝试(在使用UserControl
):
<local:VendorEntryEditView WindowName="Test Value" />
或者,如果您必须在UserControl
本身的xaml中分配此值,请通过VendorEntryEditView.xaml
的Style
分配它
<UserControl.Style>
<Style>
<Setter Property="local:VendorEntryEditView.WindowName"
Value="Blah Name" />
</Style>
</UserControl.Style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.