0

可能重复:
绑定到用户控件依赖属性

我正在尝试创建一个包含数据网格的 WPF UserControl。我希望 UserControl 通过将公开的公共属性显式绑定到托管用户控件的视图上的项目列表来获取其数据,如下所示。

如果我在 ProjectList 属性的设置器中设置断点,它永远不会进入那里。

我正在尝试将 ProjectList 属性绑定到托管视图中的项目和 UserControl 本身中的网格,我不确定这是否正确,但我认为它不会导致这个问题。

我对 UserControl 的实例化:

<uc:ProjectCardViewGrid x:Name="ProjectListUC" ProjectList="{Binding Projects, Mode=OneWay}"   Title="{Binding CreateNewPlan}" Grid.Row="1" />     

我的 UserControl 定义如下:

<UserControl x:Class="ProjectCardViewGrid"             
       ...
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
         xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" 
         xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF45"                    
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300"
         DataContext="{Binding RelativeSource={RelativeSource Self}}"
         Loaded="UserControl_Loaded_1">
<Grid x:Name="UserLayoutMaster">       
    <dxg:GridControl Grid.Row="1" x:Name="ProjectListGrid" Height="Auto" ItemsSource="{Binding ProjectList}" ShowBorder="False">

我的 ProjectList DependencyProperty 看起来像这样......

Public Property ProjectList As List(Of Project)
    Get
        Return CType(GetValue(ProjectListProperty), List(Of Project))
    End Get
    Set(value As List(Of Project))

        SetValue(ProjectListProperty, value)

        NotifyPropertyChanged()

    End Set
End Property

Public Shared ReadOnly ProjectListProperty As DependencyProperty = DependencyProperty.Register("ProjectList", GetType(List(Of Project)), GetType(ProjectCardViewGrid), New PropertyMetadata(Nothing))

编辑:这是更新的代码,但在回调事件处理程序中设置了一个断点,它仍然没有被命中。

Public Shared ReadOnly TitleProperty As DependencyProperty =
    DependencyProperty.Register(
        "Title",
        GetType(String),
        GetType(ProjectCardViewGrid),
        New FrameworkPropertyMetadata(
            Nothing,
            FrameworkPropertyMetadataOptions.AffectsRender,
            New PropertyChangedCallback(AddressOf TitleChanged)))

Public Property Title As String
    Get
        Return CType(GetValue(TitleProperty), String)
    End Get
    Set(value As String)
        SetValue(TitleProperty, value)
    End Set
End Property

Private Shared Sub TitleChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)

End Sub
4

0 回答 0