ScrollBar template behavior difference between WPF and Noesis
I've been trying to implement a ScrollBar template from ground up without copying any other template. The purpose was more about understanding than getting things done.
I started with a barebones template with just a Grid and a yellow background. I'm using noesis extension theme in the wpf app.
After some trial and error with a minimalistic example I tried the same code in Wpf and it behaved as expected.
In WPF I managed to make the scrollbar appear by setting its MinWidth to something, and that would be used as the ScrollBar width
In XamlToy
My question is, where does this behavior come from?
Is some kind of mismatch with the default values of some properties between WPF and Noesis?
I see that in your theme files you actually set this value.
I did not post this in the issue tracker because I'm not sure it is a bug or just me misunderstanding something about the default behavior in combination with a theme.
Could you shed some light on this matter?
Thanks!
I started with a barebones template with just a Grid and a yellow background. I'm using noesis extension theme in the wpf app.
After some trial and error with a minimalistic example I tried the same code in Wpf and it behaved as expected.
In WPF I managed to make the scrollbar appear by setting its MinWidth to something, and that would be used as the ScrollBar width
In XamlToy
My question is, where does this behavior come from?
Is some kind of mismatch with the default values of some properties between WPF and Noesis?
I see that in your theme files you actually set this value.
I did not post this in the issue tracker because I'm not sure it is a bug or just me misunderstanding something about the default behavior in combination with a theme.
Could you shed some light on this matter?
Thanks!
Re: ScrollBar template behavior difference between WPF and Noesis
Hey Rmunoz,
Have you tried explicitly setting the properties you're unsure about to see if that resolves the inconsistency?
Have you tried explicitly setting the properties you're unsure about to see if that resolves the inconsistency?
Re: ScrollBar template behavior difference between WPF and Noesis
Hi, thanks for answering. What i posted is the full extent of it. To summarize it.
- Created a ScrollView with several big buttons to ensure it will scroll
- Created an implicit style for ScrollBar, with no base template
- Within the template of the Scrollbar I create a Grid with a fixed yellow color to validate if the scroll area is being represented.
- Tested that document in WPF and it renders the yellow area
- Tested that document in XamlToy ( and unreal ) and it does not render the yellow area
- I tried force setting the width of the grid and it has no effect.
- I look into Noesis default theme ScrollBar style and observe it sets the MinWidth when the ScrollBar is vertical.
- Setting the MinWidth with a setter on the style to a fixed value and then it starts rendering in noesis.
- What is causing this requirement of min width to be able to observe the template?
Re: ScrollBar template behavior difference between WPF and Noesis
Found the source for the need! I was looking into the wrong template, the need for setting MinWidth does not come from any magic or misbehavior on ScrollBar.
It comes from the default template of ScrollViewer, the way it is constructed ( for the vertical case ), the second colum size is set to Auto.
This means that the ScrollBar needs to request for space in the layout pass or it will get no space. That is where the need for setting MinWidth comes from.
I add next xaml toy as a working example with a very minimal ScrollViewer template that uses a different way to request for that space.
This one is by no means better, just different, but new think I understand where it came from
The last question to be answered is, why just setting Width directly in the ScrollBar with the Default template does not work?
The ScrollViewer style sets the MaxWidth of the ScrollBar to be equal to the ScrolViewer.MinWidth.
The default value for ScrollViewer.MinWidth, seems to be 0. So if nobody sets it, MaxWidth of the Bar becomes 0.
This logic is the same for MinWith of the ScrollBar but I guess MinWidth has higher priority on space reservation, even when MaxWidth is lower than Min
Just confirmed it by spec https://learn.microsoft.com/en-us/dotne ... .0#remarks
It comes from the default template of ScrollViewer, the way it is constructed ( for the vertical case ), the second colum size is set to Auto.
This means that the ScrollBar needs to request for space in the layout pass or it will get no space. That is where the need for setting MinWidth comes from.
I add next xaml toy as a working example with a very minimal ScrollViewer template that uses a different way to request for that space.
This one is by no means better, just different, but new think I understand where it came from
The last question to be answered is, why just setting Width directly in the ScrollBar with the Default template does not work?
The ScrollViewer style sets the MaxWidth of the ScrollBar to be equal to the ScrolViewer.MinWidth.
The default value for ScrollViewer.MinWidth, seems to be 0. So if nobody sets it, MaxWidth of the Bar becomes 0.
This logic is the same for MinWith of the ScrollBar but I guess MinWidth has higher priority on space reservation, even when MaxWidth is lower than Min
Just confirmed it by spec https://learn.microsoft.com/en-us/dotne ... .0#remarks
If there is a conflict between these values, the order of application for actual width determination is first MinWidth must be honored, then MaxWidth, and finally if each of these are within bounds, Width.
-
sfernandez
Site Admin
- Posts: 3112
- Joined:
Re: ScrollBar template behavior difference between WPF and Noesis
Hi,
The template of the ScrollViewer in our theme was a bit complicated in order to achieve some cool effects when hovering over the ScrollBar area, and it was playing with the MinWidth and some scales to do that. In a basic ScrollViewer you can just specify some fixed Width (or Height) for your ScrollBars and it should work as expected.
For the ScrollBar template itself, the minimal thing you need is the Track element that should be named as "PART_Track", and then set its Thumb property with the style you want. The track also exposes a couple of buttons (DecreaseRepeatButton and IncreaseRepeatButton properties) to scroll in pages, these are the invisible buttons in the track outside the thumb.
Hope this helps a bit.
The template of the ScrollViewer in our theme was a bit complicated in order to achieve some cool effects when hovering over the ScrollBar area, and it was playing with the MinWidth and some scales to do that. In a basic ScrollViewer you can just specify some fixed Width (or Height) for your ScrollBars and it should work as expected.
For the ScrollBar template itself, the minimal thing you need is the Track element that should be named as "PART_Track", and then set its Thumb property with the style you want. The track also exposes a couple of buttons (DecreaseRepeatButton and IncreaseRepeatButton properties) to scroll in pages, these are the invisible buttons in the track outside the thumb.
Hope this helps a bit.
Re: ScrollBar template behavior difference between WPF and Noesis
Thanks for the advice! After getting past the issue with the size I managed to create a draft custom scrollbar.
There is a lot to be implemented for a fully featured ScrollBar style but I'll consider this exercise done as is :)
There is a lot to be implemented for a fully featured ScrollBar style but I'll consider this exercise done as is :)
Who is online
Users browsing this forum: Bing [Bot] and 1 guest