Link Part.Visible data binding doesn't work

Northwoods.GoSilverlight, Silverlight 4

I’m finding that data bindings for go:Part.Visible on a LinkPanel don’t work unless I set Mode=TwoWay.

I’m binding to a CLR property (“Data.IsVisible”) in my link model that correctly raises PropertyChanged events. If binding Mode is set to OneWay, the property getter is accessed only once per link, even though the PropertyChanged event is fired multiple times in response to user actions. I also debugged with a no-op IValueConverter and again found that the Convert method was only called once per link.

When I make a one-way binding from something else within the link to the same Data.IsVisible property, that binding gets updated correctly.

The workarounds are either making go:Part.Visible have a TwoWay binding as mentioned above, or manually iterating over all the Links in code and setting their Visible property. I haven’t tried turning my model property into a DependencyProperty instead of a CLR property, since the model doesn’t inherit from DependencyObject.

<go:Link.Route> <go:Route Curve="{Binding Path=Data.Curve}" Routing="{Binding Path=Data.Routing, FallbackValue=Orthogonal}" Curviness="{Binding Path=Data.Curviness}" Corner="{Binding Path=Data.Corner, FallbackValue=10}" /> </go:Link.Route> <Polygon Fill="{Binding Path=Data.Color, Mode=OneTime, FallbackValue=Black}" Points="8 4 0 8 2 4 0 0" go:LinkPanel.Alignment="1 0.5" go:LinkPanel.Index="-1" go:LinkPanel.Orientation="Along" /> <Path go:LinkPanel.IsLinkShape="True" x:Name="Path" Stroke="{Binding Path=Data.Color, Mode=OneTime, FallbackValue=Black}" StrokeThickness="{Binding Path=Data.Thickness, Mode=OneTime, FallbackValue=2}" /> <TextBlock Text="{Binding Data.IsVisible, Mode=OneWay}" go:LinkPanel.Index="0" go:LinkPanel.Offset="NaN NaN" go:LinkPanel.Orientation="Upright" /> <TextBlock Text="{Binding Data.MidText}" go:LinkPanel.Offset="0 NaN" go:LinkPanel.Orientation="Upright" /> <TextBlock go:LinkPanel.Index="-1" go:LinkPanel.Offset="NaN NaN" go:LinkPanel.Orientation="Upright" /> </go:LinkPanel> </DataTemplate>

Here's the relevant property in the link model:

<> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}


public bool IsVisible
get { return isVisible; }
if (isVisible == value)
isVisible = value;
“IsVisible”, !isVisible, isVisible);

Is this a known bug? Any idea what might be causing this?

I suspect you are also setting Part.Visible explicitly by assignment or implicitly by expanding/collapsing subtrees or subgraphs.

Doing so would provide a local value for Part.Visible that would take precedence over the data-binding.

Just for fun I modified the Decision Tree sample to data-bind Part.Visible with Mode=OneWay, and it worked fine.

I just made a minimal example of the issue (1 MB zip file). Run it, and then try changing the binding mode in the LinkTemplate resource in MainPage.xaml.

OK, what’s happening is that PartManager.OnLinkAdded is setting Part.Visible, which happens to clobber the OneWay data-binding.

It’s possible to override this method so that it only sets Part.Visible if the value needs to change. That’s what we’ll do for version 1.2.

Can you use Mode=TwoWay in this one case, at least until you upgrade to a yet-to-be-released version 1.2?

Yes, Mode=TwoWay is fine (I just need to toggle the model’s visibility flag twice at startup to get the binding to sync up).