0

重複の可能性:
usercontrolsdependencypropertiesへのバインド

データのグリッドを含むWPFUserControlを作成しようとしています。以下に示すように、公開されたパブリックプロパティを、ユーザーコントロールをホストするビュー上のプロジェクトのリストに明示的にバインドすることにより、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">

私のProjectListDependencyPropertyは次のようになります...

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