我试图创建一个包含数据网格的WPF UserControl。我希望UserControl通过将公开的公共属性显式绑定到托管用户控件的视图上的Projects列表来获取其数据,如下所示。
如果我在ProjectList属性的setter中设置断点,它就永远不会进入。
我试图将ProjectList属性绑定到托管视图中的Projects和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))
编辑:这是更新的代码,但在Callback事件处理程序中设置断点,它仍然没有被击中。
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