Partially vertically scroll - c#

I have a ListBox that contains two columns - column one contains a Toggle Button, column two contains an Expander with multiple controls within it. If the expander is collapsed, the overall scrolling of the ListBox works fine. However, if the Expander is open and the expander contains a large quantity of items, the ListBox will scroll the entire row size, often not showing part of the expander list.
This would be similar to placing an image in the list box that is larger than the viewable area of the list box. In this case, if you click the scrollbar, you would want to "step" down the image, without it scrolling off the screen in one click.
Is there a setting for the ListBox that will allow the partial scrolling as I've described? My listBox is defined in a xaml, the controls are added via C# code.

Have you tried turning on smooth scrolling by setting ScrollViewer.CanContentScroll to false? This is what controls whether the ScrollViewer will scroll an item at a time, or smoothly with partial items available.
"ScrollViewer currently allows two scrolling modes: smooth
pixel-by-pixel scrolling (CanContentScroll = false) or discrete
item-by-item scrolling (CanContentScroll = true). Currently WPF
supports UI virtualization only when scrolling by item. Pixel-based
scrolling is also called 'physical scrolling' and item-based scrolling
is also called 'logical scrolling'."
(From this answer).
If you have a lot of items in your ListBox, this may not be an ideal solution, however, because it turns off Virtualization, and therefore may have a performance impact. Take a look at this answer to see more about smooth scrolling and virtualization. (One answer suggests a hack that allows for smooth scrolling and virtualization).

Related

WPF ListView scroll whole page (seen items) by button click

I've created a listview in WPF. The items in there are changing their backgroundcolor by clicking, in this case i deactivated the listview prop 'Focusable'.
For my usecase (on a touchscreen) i want to hide the scrollbar and just scroll by clicking an up/down button at the bottom. One click should scroll the whole page (UP/DOWN) and show the next (so far hided) items.
I'm seraching for a flexible solution and don't want to calculate pixels or smth like that (also the items haven't a fixed height, also the window)
Thanks in advance
First off, it might benefit you to take a look at How do I ask a good question?. Specifically, in your case it would be easier to understand the sitution if you included some of your XAML. However, I do think I have a solution for you.
ItemsControls like the ListView support "content scrolling", meaning the ability to scroll by content/items instead of by pixel. This question gives a solution to finding which items are currently visible in the ListView by accessing the internal ScrollViewer. ScrollViewer.VerticalOffset will tell you the index first visible item and ScrollViewer.ViewportHeight will tell you how many items are visible. To scroll to the "next page", you should just need to:
ScrollViewer.VerticalOffset += ScrollViewer.ViewportHeight;

Virtualize GridView inside ScrollViewer in Windows Store App

I have the following application:
I am developing a Windows Store app in which I need to show a big grid filled with buttons. The content of the buttons are some numbers and when I click any of them, I open a Popup with editor, where I edit those numbers. For that purpose I use a GridView, I put an ItemsWrapGrid as ItemsPanel. This makes the grid look exactly as I need it to look. I put the GridView inside a ScrollViewer, because I need to scroll the grid in both directions, since it has a lot of elements. Also I need to have the pinch-to-zoom effect that the ScrollViewer gives out of the box. I need to change the ItemsSource for that GridView when the user chooses different source in a ListView next to the GridView.
The problem:
Putting the GridView inside the ScrollViewer breaks the Virtualization inside and this has a major impact on my performance. When I switch the ItemsSource of the GridView, it takes more than 3-4 seconds for the rendering and during that time, the UI is frozen.
My question:
How can I keep the awesome stuff that the ScrollViewer gives me and also keep the virtualization? Because when I remove the ScrollViewer, changing between the ItemsSources happens almost instantly.
Any idea?
You'll be best off implementing virtualization yourself since you're trying to use the GridView far from the use cases it was designed for.
Put a Canvas in a ScrollViewer that does both pan and zoom and handle view change events on the ScrollViewer by laying out item containers inside and around the viewport. Avoid unnecessary changes too, so keep containers in place if they are to stay realized between view change events and recycle containers that are leaving the viewport neighborhood.

how to add scroll-bar to windows store app?

I am making an app for windows store; Like in c# we used Scroll bars to move down to the end of page and view all content, How can we do it for windows store? Like how to arrange data and use scroll bars to move to right and view all the data?
Typically you don't use ScrollBar controls directly and rather put your content in a Panel (usually Grid/StackPanel/Canvas) and put that panel inside of a ScrollViewer. Make sure to set Horizontal/Vertical-Scroll-Mode/BarVisibility and ZoomMode properties to match the direction of scrolling you want supported.
The benefit of using the ScrollViewer instead of ScrollBar is that you get smooth panning with touch that the platform handles for you with the Direct Manipulation layer that is not exposed to you in WinRT/XAML and also handles all the other inputs in a standard way.
Also if you are dealing with a list of items you want to scroll through, especially when the list is long - you would use some ItemsControl subclass - typically a vertical ListView for long, mostly text content lists or horizontal GridView for lists of richer media items. The benefit of using those is that they handle list virtualization for you - i.e. for lists of thousands of items you only get few item containers generated for the items currently visible in the control's view port and ones that are near the view port so they are ready when you scroll to them.
The templates of these list controls internally already have a ScrollViewer and the ScrollViewer's template has ScrollBars inside.

WinRT - Is item rendered?

Is it possible to check has item already been rendered (therefore visible to user) on screen? I am trying to create image control with automatic "image swapping animation" but when I have hundreds of images on page (for instance in GridView) performance is terrible. I'd like to know which controls are visible to user so I'd run animation only for them.
You can check the item's position by getting UIElement.TransformToVisual() and then using it to get the coordinates of the item relative to the clipping frame of the ScrollViewer in your GridView, but the performance of it might not be very good if you check it on each ScrollViewer view change event and could use some optimization, which would also be difficult if your GridView supports virtualization, which it needs to if you want to be able to scroll through hundreds of images.
Oleh's suggestion is your best best if you don't want to spend days or weeks figuring it out. Your GridView will be virtualized if you use a virtualizing panel for its ItemsPanel property, e.g. a WrapGrid (Windows 8.0 default) or ItemsWrapGrid (Windows 8.1 default). Note that VariableSizedWrapGrid is NOT virtualized.

Datagrid scrolling in Windows s Mobile way to get rid of scroll bar?

I have a very simple form using the compact framework. I have two search fields a search button and a datagrid. The button sets the DataSource for a DataGrid on the form. I know that I can set the height and width on the DataGrid but I don't want the user to have to use the scroll bars on the DataGrid as it has a few hundred records. I just want the user to use the scroll bar on the form to scroll. How do I accomplish this?
I am assuming that the behavior you want is for a vertical scroll bar that spans the total height of the form to navigate through the records of the DataGrid. This DataGrid does not take up all the space on the form.
You could add a VScrollBar to the side of the form and set its Maximum to the total row count of your DataGrid. Then attach to the ValueChanged event of the scroll bar and manipulate the selected row of your DataGrid. This in effect would be mimicking the scrolling behavior of the DataGrid.
The tricky part is hiding the scroll bar of the DataGrid, as there is no property to hide it. You can extend its width so that the scroll bar is rendered off screen, but remember to set the Form's AutoScroll property to false so that it does not render a Horizontal scroll bar that would reveal the DataGrid kludge.
Based on your application, you may want to look into using a ListView with the View property set to Details. The ListView is much easier to manipulate in the compact framework and might fit your application better. You can still use the same VScrollBar technique above and apply it to the ListView if you wish.
You must get the rowcount from the DataSource. Cast it like the enclosed example to produce the row count: (rsMissingItems is a SqlCEResultSet object)
Dim intRecCnt As Int32 = DirectCast(rsMissingItems.ResultSetView, ICollection).Count

Categories

Resources