I'm using a ScrollViewer to display an Image. The Image has a ScaleTransform set as one of it's LayoutTransforms. I've got it setup to fit the width of the image into the ActualSize of the ScrollViewer. My problem is that if the image height requires the vertical scrollbar to be present (I have it set to Auto) then my image is scaled just a little bit to much. I know how to determine if the scrollbar would be present and how to get the correct scale, but I cannot figure out how to determine what the actual width of the scrollbar is. I guess I could just guess at it, but I'd like something that would work if I later add styles to my application that would result in the scrollbars being a different size. Additionally I'm also doing Fit to Height and would need to get the Height of the horizontal scrollbar when it would be visible (I'm assuming that the answer to getting the width of the vertical scrollbar would make getting the height of the horizontal scrollbar obvious).
You can use SystemParameters.ScrollWidth.
Using ViewableHeight and ViewableWidth instead of ActualHeight and ActualWidth in my scaling calculations along with setting the scroll bars Visibility to Visible instead of Auto works. However I'll accept another answer that allows the scroll bars to be set to Auto instead.
Edit:
OK, I've now got the scroll bars set to Visible. Then I do my calculation with the ViewableHeight and ViewableWidth. Then I set the scroll bars back to Auto. This seems to work even if it's not all that elegant.
Related
I use a RadGridView (a GridView from telerik libraries) and I resize the rows height for simulate a zoom.
The issue is that the scrollbar values become wrong after a zoom. I receive the values ExtentHeight (total virtual height of my RadGridView) and a VerticalOffset (my position), and both are false.
As I know the individual height of every cells, I can manually calculate the ExtentHeight, but not the VerticalOffset. And the concern is that I have synchronized my grid with a scrollbar which gives a render of the RadGridView, and it can’t be synchronized with these bad values. The only solution is to scroll all the RadGridView, and the scrollbar will be updated with the new heights of its children.
You can see an example in this video, where I scroll after a zoom, and it’s not working. Then I scroll all the grid (with the down arrow), and it works after.
https://youtu.be/QqvTnYK5A6o
So how my scrollbar can automatically updates the values of its content ?
The method scrollBar.UpdateLayout(); doesn't work unfortunaly.
Thanks !
The solution is to set the property EnableRowVirtualization of the RadGridView to false, but it causes a big performance problem unfortunately.
I have a header that is set at a minimum width of 960px and is fixed to the top of the page. When the user shrinks the window to a size smaller than 960px, the horizontal scrollbar appears, as it should. However, when the user scrolls horizontally, since some of the header is cut off, I would like to be able to scroll the header at the same rate as the page... I pretty much want my header fixed vertically, but not horizontally.
I've looked at the following, but no help:
CSS: fixed position on x-axis but not y?
Centering a fixed element, but scroll it horizontally
I know this is a dated question and am not sure if you figured it out yet, but wanted to submit an answer in case someone else has the same problem.
When you set content to fixed in CSS with a minimum width, it is locked relative to the window on both axes. When the window is resized to less than minimum width, the excess header/footer is clipped and cannot be scrolled to. Unfortunately, there is no way to change this behavior in CSS alone. There is, however a simple jQuery fix for your problem (assuming you already have other content on the page that will create the horizontal scroll bar):
$(window).scroll(function ()
{
$("header,footer").css('margin-left', -($(window).scrollLeft()) + "px");
});
This will cause the header and footer (as appropriate) to move on the x axis in the opposite direction of the scroll, thus achieving your desired effect.
I like to be avble to resize the form by dragging its right side border...so I set BorderStyle to sizable, but at the same time I don't want to be able to resize it by dragigng its Bottom border, So I want to be able to resize the form horizontally but not vertically.
I thought well if I set the same value of the Height for both MinSize and MaxSize proprieties it should work but nop! as soon as I enter a non-zero value for Height it starts to think that Zero for Width is also important...which is wrong.
If I need to "code" for it, then never mind. Not worth of it. But if there some properties I can set I my form to do this, that would be great.
Set MaximumSize to be {99999, yourHeight} and MinimumSize to be {0,yourHeight}. The designer does indeed think that the zero dimension of a nonzero size is important; so don't specify a width of zero as the maximum.
I have canvas which is placed on scrollviewer in order to allow scrolling. Is it possible to get coordinates of visible part of canvas?
I was trying to calculate it that way
leftBorder = ScrollViewer1.HorizontalOffset;
rightBorder = ScrollViewer1.ViewportWidth - ScrollViewer1.HorizontalOffset;
topBorder = ScrollViewer1.VerticalOffset;
bottomBorder = ScrollViewer1.ViewportHeight - ScrollViewer1.VerticalOffset;
but it seems that it is not working.
The Horizontal and Vertical offset is the actual scroll value in that direction.
Besides that, if you want the size of the content without any scrollbars that might be visible.
You can search for the child named "PART_ScrollContentPresenter". This shows the actual content of the scrollviewer, and this content will be resized when the scrollbars needs more space.
Hope that helps.
For a day now I'm struggling to solving this issue, regarding scaling a textblock and a textbox upon pinching the scatterViewItem for resizing it.
I've tried putting each of the elements in their viewbox, but also having the whole grid in a viewbox.
The issue is that it(the textbloxk, that is) doesn't scale upon pinching or stretching rather, (dynamically so to speak) - at runtime, or not even upon contact_up.
What actually solves it is simply setting an event handler that fires upon size_changed of the SVI, inside simply paste the code:
{label name}.FontSize *= (double)e.NewSize.Height / (double)e.PreviousSize.Height;
Thanks!
I am assuming you mean that the TextBlock in the window does not scale when resizing the window...? Have you tried putting a ViewBox in a Grid that contains the item you want to resize? If you have the item in a ViewBox, and set the Height and Width of the ViewBox to Auto, is should resize with the window...I hope this helps a little.