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

Change RadDiagram ScrollBars SmallChange Property

2 Answers 22 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Adrien
Top achievements
Rank 1
Adrien asked on 11 Jan 2021, 09:44 AM
Hello there !
Happy new year all !

I'm trying to do a little change on the standard ScrollBars linked to a RadDiagram.
What I'd like to accomplish is to reduce the move made on the diagram when we click on the two RepeatButton of the ScrollBar.

To manage this modification on the ScrollBar, we usually modify the property SmallChange to adapt to the behaviour we want.

So I tried to add the property in the ScrollBar style used in our telerik:RadDiagram:Resources, but it doesn't change anything apparently.
Then I read that this property is bypassed by the framework when the ScrollBars are in a ScrollViewer (https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/ScrollViewer.cs,b3cec2f89df004cd).

My second try was to add a new ControlTemplate for the ScrollViewer of the RadDiagram, and link it to my ScrollBar Style with the property updated.

However I just read on a topic here that it's not really a ScrollViewer that is added when we set the ScrollViewer.HorizontalScrollBarVisibility/ScrollViewer.VerticalScrollBarVisibility of the RadDiagram to Visible, but only ScrollBars.

I'm a little bt stuck on this issue.

Did I did/understand something wrong about this or is there any way to change the standard move effect on the RepeatButton of the RadDiagram ScrollBars ? 

Thanx a lot for reading this, and maybe help me :D


2 Answers, 1 is accepted

Sort by
0
Dinko
Telerik team
answered on 13 Jan 2021, 10:29 AM

Hello Adrien,

Thank you for your interest in our RadDiagram framework for WPF.

You are right that the SmallChange/LargeChange property is not respected when you set it to Vertical/HorizontalScrollBar. Internally, in our code, the SmallChange property is recalculated on every Zoom/Position changed, etc. After trying a few approaches on my side, I think I found a suitable one. In a few words, you can get the ScrollBars in the Loaded event of the RadDiagram. Then you can subscribe to the ZoomChanged and PositionChanged events. In their event handler, you can set the SmallChange properties wrapped inside Dispatcher.BeginInvoke() method. This way, you can assure that your value is set after the RadDiagram internal code set. Don't forget to set the DispatcherPriority to ApplicationIdle. Check the following code snippet, which will better demonstrate what I have in mind.

public partial class MainWindow : Window
{
	public MainWindow()
	{
		InitializeComponent();
					
		this.diagram.Loaded +=diagram_Loaded;
		this.diagram.ZoomChanged += Diagram_ZoomChanged;
		this.diagram.PositionChanged += Diagram_PositionChanged;
	}
	
	public ScrollBar VerticalScrollBar { get; set; }
	public ScrollBar HorizonrtalScrollBar { get; set; }

	private void Diagram_PositionChanged(object sender, Telerik.Windows.Controls.Diagrams.PositionChangedRoutedEventArgs e)
	{
		Dispatcher.BeginInvoke((Action)(() => {

			VerticalScrollBar.SmallChange = 1;
			HorizonrtalScrollBar.SmallChange = 1;

			VerticalScrollBar.LargeChange = 1;
			HorizonrtalScrollBar.LargeChange = 1;
		}), System.Windows.Threading.DispatcherPriority.ApplicationIdle);
	}

	private void Diagram_ZoomChanged(object sender, Telerik.Windows.RadRoutedPropertyChangedEventArgs<double> e)
	{
		Dispatcher.BeginInvoke((Action)(() =>
		{
			VerticalScrollBar.SmallChange = 1;
			HorizonrtalScrollBar.SmallChange = 1;

			VerticalScrollBar.LargeChange = 1;
			HorizonrtalScrollBar.LargeChange = 1;
		}), System.Windows.Threading.DispatcherPriority.ApplicationIdle);
	}

	private void diagram_Loaded(object sender, RoutedEventArgs e)
	{
		VerticalScrollBar = this.diagram.ChildrenOfType<ScrollBar>().FirstOrDefault(x => x.Name == "VerticalScrollbar");
		HorizonrtalScrollBar = this.diagram.ChildrenOfType<ScrollBar>().FirstOrDefault(x => x.Name == "HorizontalScrollbar");
	}
}

Regards,
Dinko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Adrien
Top achievements
Rank 1
answered on 13 Jan 2021, 01:12 PM
Hi Dinko !

Thanx a lot for your answer.

It seems to works like a charm so far !

We'll make more tests to verify everything but it seems good.

Have a good day.
Tags
Diagram
Asked by
Adrien
Top achievements
Rank 1
Answers by
Dinko
Telerik team
Adrien
Top achievements
Rank 1
Share this question
or