views:

250

answers:

2

Hi All,

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.

A: 

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).

Aviad P.
Thanks for your response Aviad.I do believe my Group object implements INotifyPropertyChanged for the Visibility property, as my Group object inherits from UserControl. Would you agree?
Frank
Does it also actually raise the `PropertyChanged` event in the `Visibility` property setter? This has to be done explicitly.
Aviad P.
UserControl does *NOT* implement INotifyPropertyChanged. However, if Group is a UserControl, then Group.Visibility is a dependency property, and therefore shouldn't need to raise change notifications to be a binding source. You might want to post a bit more of the Group definition to help diagnose the problem.
itowlson
Thanks for that Clarification ITowlosonThe group definition is simple.<UserControl x:Class="Group" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="0" Height="0"> </UserControl>Partial Public Class Page Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Me.Visibility = Windows.Visibility.Collapsed End SubEnd Class
Frank
A: 

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
Frank