0

我的代码背后有我想在 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 中收到一条消息:

<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 中设置该属性?谢谢!

4

1 回答 1

1

也许只是尝试(您在哪里使用您的UserControl):

<local:VendorEntryEditView WindowName="Test Value" />

或者UserControl如果您必须在自身的 xaml 中分配此值,请通过Stylein分配它VendorEntryEditView.xaml

<UserControl.Style>
  <Style>
    <Setter Property="local:VendorEntryEditView.WindowName"
            Value="Blah Name" />
  </Style>
</UserControl.Style>
于 2013-04-24T17:25:48.653 回答