开发者

WPF Bind to DependencyProperty of another Object?

I am working on a WPF application similar to visio. I would like to be able to logically group some of the items in my diagram, each of which is a UIElement, and control certain behaviors (i.e. visibility) at the group level.

My first attempt at this was to create a control, called a Group, which had width & height = 0. I wanted to assign to my diagram elements a specific "Group" through their group property, and then bind certain UIElement properties to the group value, as below:

<DiagramNode  
         Width="300" Height="300" 
         Visibility="{Binding RelativeSource={RelativeSource Self},Path=Group.Visibility}"
         > ... </DiagramNode >

Although this does not开发者_运维百科 throw a binding error, it also doesn't work. Changing the Visibility of the group has no affect on the visibility of the nodes assigned to that group. No errors appear at anytime as far as i can tell, it just doesn't work.

Any ideas? Is my approach possible? If no, any one have alternatives they'd like to suggest :). I'm not a huge UI guy, feel much more comfortable in a service layer, so I'm open to other suggestions.


If there really is no binding error in the trace of the application when run through the debugger, then the problem is probably in change notifications. You must make sure that the Visibility property of your Group object provides change notifications when changed.

This is usually done by implementing INotifyPropertyChanged on the class, and in the set accessor raising a PropertyChanged event (if the value actually changed).


Is the issue perhaps in my property declaration of the Group object of my DiagramNode class?

Public Class DiagramNode
...
Private _group As Group
Public Property Group() As Group
    Get
        Return Me._group 
    End Get
    Set(ByVal value As Group)
        Me._group = value
    End Set
End Property
...
End Class
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜