[英]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.