This is a migrated thread and some comments may be shown as answers.

Refresh RadDiagramNavigationPane

2 Answers 179 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
ManniAT
Top achievements
Rank 2
ManniAT asked on 12 Oct 2013, 06:52 PM
Hi,

I have a RadDiagram and changed the Shape Style to have a good visible selection rectangle.
Further I added a RadDiagramNavigationPane.

The problem - the preview doesn't update.
To reproduce
- start the application, select a shape.
- open the RadDiagramNavigationPane

Now (as expected) I can see the selected Shape.

Next I select a different Shape - the preview in the RadDiagramNavigationPane doesn't reflect this change.
Opening / closing the RadDiagramNavigationPane doesn't change anything.
But if I mess around with my window (change size or move to a different screen) the preview is redrawn.
And the newly selected shape is now also select in the preview.

I guess I can't ask my users to resize there window to see changes in the preview :)
Just kidding - the question is - is there a way to enforce such a refresh?

By the way - I use MVVM - so a "On....Event" in code behind is not what I'm searching for.

Thanks
Manfred

2 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 14 Oct 2013, 04:11 PM
Hi Manfred,

The RadDiagramNavigationPane exposes a RefreshThumbnail() method, which you can use to manually refresh the thumbnail when a new RadDiagramItem is selected. However, you need to keep in mind that the SelectionChanged event in the RadDiagram is fired too early and you cannot directly use it to update the NavigationPane - instead you will have to use a dispatcher.

Also, as you said you're using MVVM and you don't want to attach event handlers you can try creating a custom NavigationPane. This will allow you to attach an event handler for the RadDiagramNavigationPane associated diagram and update the thumbnail:
public class CustomNavigationPane : RadDiagramNavigationPane
{
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        if (this.Diagram != null)
            this.Diagram.SelectionChanged += Diagram_SelectionChanged;
    }
 
    void Diagram_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
    {
        Dispatcher.BeginInvoke(new Action(() => { this.RefreshThumbnail(); }), DispatcherPriority.ApplicationIdle);
    }
}

I attached a sample solution to demonstrate this solution so please have a look at it and let me know if it helps.

Regards,
Tina Stancheva
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
ManniAT
Top achievements
Rank 2
answered on 14 Oct 2013, 05:23 PM
Hi Tina,

thank you for this solution.
I didn't try your sample - but implemented your code - and this works like a charm!
My Code
public class XDiagramNavigationPane : RadDiagramNavigationPane {
    protected override void OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) {
        base.OnPropertyChanged(e);
        if(e.Property.Name == "Diagram") {
            RadDiagram dGram = e.OldValue as RadDiagram;
            if(dGram != null) {
                dGram.SelectionChanged -= Diagram_SelectionChanged;
            }
            dGram = e.NewValue as RadDiagram;
            if(dGram != null) {
                dGram.SelectionChanged += Diagram_SelectionChanged;
            }
        }
    }
 
    private void Diagram_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) {
        Dispatcher.BeginInvoke(new Action(() => { this.RefreshThumbnail(); }), DispatcherPriority.ApplicationIdle);
    }
}


Thank you
Manfred
Tags
Diagram
Asked by
ManniAT
Top achievements
Rank 2
Answers by
Tina Stancheva
Telerik team
ManniAT
Top achievements
Rank 2
Share this question
or