Refresh RadDiagramNavigationPane

3 posts, 1 answers
  1. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 12 Oct 2013 Link to this post

    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. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 14 Oct 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 14 Oct 2013 Link to this post

    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
Back to Top