XAML Vertical Scrolling Grid within a Horizontal ScrollViewer - c#

I'm trying to recreate the layout of the Weather app in XAML / C#. I have a ListView full of ListViewItems. It is one of several objects within a ScrollViewer. The end result should be that the user can scroll horizontally through the Objects, but stop on the ListView and scroll vertically.
For the effect to work, the ScrollViewer must match the height of the page, and the ListView must match the height of the ScrollViewer, without stretching it.
I can't figure out how to do this without using code-behind to find the Window.Current.Bounds and apply the height to the ScrollViewer, this seems like a dirty hack. Is there a way to do this purely in XAML?

The ListView has its own scrollbar stuff, without needing a ScrollViewer. Otherwise to make things stretch it should be pretty easy - how are you putting things in the ScrollViewer? Through a Grid? A StackPanel?

This may be what you are looking for, but you may find it useful to achieve a 'weather app' look and feel:
http://dotnetbyexample.blogspot.co.uk/2012/08/a-winrt-behavior-to-turn-flipview-into.html

Related

Custom Scrolling with ListView

I've been tasked at work with creating a UserControl containing a ListView and ComboBox's for sorting the ListView data. Sorting with the Combobox's s the easy part; the part with which I'm having difficulty is implementing a method of scrolling. In the end, the control should have an Excel-like feel to it. However, sometimes the ListView is too tall or wide for where it is placed. Therefore, there two be two scrollbars somewhere on the control. One vertically moves of the ListView only, and the other moves both the ListView and ComboBox filters horizontally.
Please note in the image above that the ComboBox's do adjust themselves according to column width, but the code for that is not enabled at the moment.
What I've tried: In the control, the filter boxes are in their own panel, and the ListView has had its own panel at times. I've tried using various combinations of the HScroll/VScroll and HorizontalScroll/VerticalScroll properties and the native function ShowScrollBar() for all the controls, but nothing has worked. The only way I've gotten scrollbars to appear is by settings AutoScroll (Scrollable for the ListView) to true. Of course, the scroll bars come in pairs and work only on the same control. I also attempted to programmatically move the scroll bars, but I haven't been able to accomplish that, either.
I've got to be doing something wrong, but I'm not sure what it is. Any help is appreciated!
I think I'd go for a different solution.
If you put the ComboBoxes in a AutoSrcoll panel with the same Anchors as the ListView you would give your users the freedom to scroll the two independently.
Yes, a ScrollBar would appear and take space but I would still happily sell that as a feature, not a bug ;-)
As for handling the Scroll event of a ListView: It is hidden and you'll have to subclass it to get access to it. See here

Custom scrolling in Winforms c#

I am developing an application that will use touch screens to navigate for use in a warehouse environment.
There is a need to present a list to the users and because this list could be quite long, the user will at some point need to scroll down the list.
As you all know the system scroll bars for panels and textboxes etc is quite small and I would like to know if I can either resize the controls that make up the scroll bar (the little arrows at the top and bottom, and the place holder bar in the scroll bar itself), or if I can create a couple of buttons that can scroll up and down my control for me?
Thanks,
Karl
Answer pulled from this post.
Check this out:
Winforms - Adjust width of vertical scrollbar on CheckedListBox
Worth mentioning too:
.NET Compact framework - make scrollbars wider
More of the same, but this time with a better solution through the use of the scrollbar control:
Change the width of a scrollbar
Another one in which the guy teaches how to create your own scrollbar control (interesting):
Set the Scrollbar width of a DataGridView
The last one (worth trying):
Is there a way to get the scrollbar height and width for a ListView control
You can add your own scroll buttons and programatically scroll like so:
myPanel.VerticalScroll.Value++;

WPF datagrid scrolling issue

there is a search View ( app is a MVP - PRISM WPF ) which had some issue with scrolling. it took hell of a long time to scroll when you click the scroll bar buttons. Click and dragging the scroll bar was even worse!!
considering i like anomalies, i picked it and started looking into what was going wrong. I suspected many things, but evidently the issue with the datagrid scroll was due to "ScrollViewer.CanContentScroll=True" i removed it and the scrolling was a pleasant experience compared with earlier.
Now i was wondering why my developers had put that property as true, with in couple of mins i found Doing a Page down was scrolling more than a page with out the CanContentScroll property marked true!
Now i need the scrolling to be faster AND i also need page down and page up to scroll as expected! Can some one tell me What I am missing here?? thanks!
I had similar issues with my datagrid : slow scrolling, and also randomly size changing scrollbar.
I did the following:
simplify the templates of the cells (no more nested borders and multiple colors, ToggleButtons instead of CheckBoxes)
in code use frozen colors.
this helped speed things up but did not solve the issue.
Then i set the row / cells templates height and also the RowHeight property, and then it was ok : i had both smooth scrolling and normal scrollbar. So i guess that the DataGrid was unable to compute the size of what remained to be displayed that made both the scroll slow and the scrollbar having changing size.
(Yet the rows / cells were all having same actual height in their templates since they were defined with same controls but Height property was not set...)
Hope that can help.

dockpanel alternatives

I have read that I can't have my dockpanel scroll so im looking for alternatives
I want to have a lot of slider controls(unknown number) left to right in a panel of some sort that can scroll so I can view all the sliders. I tried with dock panel but of course that didn't work. What can I do to make the dockpanel work or what do I replace dockpanel with(the replacement would need to support children)?
Thanks!
EDIT:
http://i.stack.imgur.com/J5a4u.png
here is the idea but it needs to scroll horizontally
David Brunelle Does work but its not quite what I want. Id like the scroll bar to be on the top of the control and not attached to the bottom of the window.
I'm not sure I understand, but you can use a panel within a ScrollViewer
Something like this :
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Margin="2,2,2,2">
...
</StackPanel>
</ScrollViewer>
This will allow for vertical scrolling. You could do the same for horizontal scrolling. I do not know if this would work with a docking panel, but I know it does with a stack panel.
Hope that helps.
I would use a ListBox as it will handle the scrolling part for you, then you can set the ItemTemplate (if you want) and you can use data binding (using an ObservableCollection or a DataView

How to adjust WrapPanel height dynamically based on content?

I'm developing a WPF application. In this application, I have a Window which contains a WrapPanel. Inside the WrapPanel are a series of StackPanels which have varying heights, but all the same width. The number and size of the StackPanels is not known at design time (they are generated dynamically).
These StackPanels normally stack fine on top of each other, and then "wrap" to another column when there is no more room in the WrapPanel. To achieve this, I had to set a fixed height for my WrapPanel (with the height set to "Auto", it would continue down the page instead of wrapping to another column). However, when by chance I have a StackPanel that is too large to fit in the WrapPanel height, it is simply truncated. An image of this situation is below.
My question is, can I query the height of each StackPanel before I Show() this to the user, and set the WrapPanel height based on the largest StackPanel? Is there a better way to do this?
First, have you ensured that this issue is not caused by the WrapPanel reaching its maximum available dimensions (i.e. if its size is being constrained by its parent Window or element)? Because if this is the case, then you'll need to either look at restructuring your overall layout, or wrap it in a ScrollViewer.
If the above is not the case, and the WrapPanel has plenty of room to 'grow', this does indeed seem like a strange issue. You say the StackPanels are generated dynamically. So in your code, you must be calling myWrapPanel.Children.Add(stackPanel). After this line of code, you could try adding something like the following:
myWrapPanel.Height = myWrapPanel.Children.Cast<FrameworkElement>().Max(e => e.ActualHeight);
EDIT: just realized this will only work if a single StackPanel takes up the entire height, as in your image. but perhaps it will start you on the right track!

Categories