Override OnScaleChanged

Hi,

I’m using GoXam 1.0 in Silverlight.

I’m trying to update the value of a combobox depending on the value of the diagram scale.

By default, the keyboard “+” and “-” button scale up and down the diagram and the CTRL + mouseWheel as well.

I would like to be able to set the value of my combo box when those event appears. But i don’t know in which event to put my code in order to intercept those behavior and update my combo box.

MoreOver, in the .chm file, it’s written that i should be able to override the diagramPanel OnScaleChanged method. But i don’t understand how, because the Diagram.Panel property is read only.

Can you explain me how to do that ?

It’s easiest to implement a DiagramPanel.ViewportBoundsChanged event handler. There’s an example of this in the GoXamIntro.pdf documentation, although for the purpose of exchanging templates instead of modifying a different control.

The only tricky part is making sure you establish the event handler on the Diagram.Panel after the panel has been created due to the expansion of the Diagram’s ControlTemplate. So you have to set up that ViewportBoundsChanged event handler inside an event handler for the diagram being Loaded, or at a later time when the Diagram.Panel exists.

Oh, and if you really want to override a method on DiagramPanel, to make use of your custom DiagramPanel-inheriting class you need to set the Diagram.Template to a ControlTemplate that makes use of your class.

The GenericSilverlight.xaml file in the docs folder shows you the standard template definition for Diagram. You can copy that and perhaps you can simplify it for your own purposes while adapting it to use your panel class instead of go:DiagramPanel.

Thanks a lot.
i used the DiagramPanel.ViewportBoundsChanged event solution and it worked.

For others, that’s what i have done :

Add the event handler

Private Sub MainDiagram_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MainDiagram.Loaded
        ' Ajout d'un handler pour gérer l'evenement ViewportBoundsChanged du panel (MainDiagram)
        AddHandler Me.MainDiagram.Panel.ViewportBoundsChanged, AddressOf MainDiagramPanel_ViewportBoundsChanged
    End Sub

Implement the function linked to the event

Private Sub MainDiagramPanel_ViewportBoundsChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Rect))

' I do my stuff here

End Sub

In version 1.1 we have added a Diagram.TemplateApplied event, which is a better way of initializing the DiagramPanel.

The reason that it’s better is that the Loaded event may occur multiple times, which makes the above code undesirable if the diagram (or whatever it’s a part of) is repeatedly unloaded and reloaded.