I'm trying to add portrait support to a page containing a GridView that uses a VirtualizingStackPanel as its ItemsPanelTemplate. The idea is that when the orientation changes, I'd be able to change the Orientation property of the VirtualizingStackPanel to scroll vertically in portrait and horizontally in landscape. However, since the VirtualizingStackPanel is used as a template, I can't directly access it by name in the code behind.
Is there any way to accomplish what I want?
I could just make a duplicate of the GridView (or use a ListView) and Visual States to show/hide them appropriately, but I'd prefer not to duplicate so much code.
Use VisualTreeHelper to dig into the GridView's visual tree and find the panel.
There is some kind of bug when changing the orientation.
var zoomedInStackpanel = itemGridView.ItemsPanelRoot as VirtualizingStackPanel;
zoomedInStackpanel.Orientation = Orientation.Vertical;
I gave up and used two GridViews. One for each orientation
Related
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
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
I saw a question here showing to use this:
button.Visibility = Visibility.Hidden;
but I only have Collapsed or Visible, and Collapsed removes the button which changes the layout of the controls which I don't want.
Any ideas on how to solve this?
Apparently you are on the Silverlight framework which doesnT have the Hidden option.
Silverlight does not support the Hidden Visibility state.
You can see the available members in both .Net framework and Silverlight in the reference . (use the dropdown on top of the page to switch between different platforms)
A crooked solution to your problem could be setting the opacity of the UI element to 0 but this approach is known to have performance drawbacks.
Another solution if you don't want to resort to changing the Opacity would be encapsulate the button within a Grid and set the Grid height property to fixed size corresponding to the button height. Now you can Collapse the button without other controls rearranging themselves.
Cheers,
Anders
I have many nodes and some of them are under the screen's edge. Tho treeview is scrollable, there is no vertical scrollbar on the right. How can i show it?
Did you happen to set the Scrollable property to false? If it is set to true, the control should display the scroll bars.
This "bug" can be replicated, but there is a workaround.
I have found that if you place a TreeView within a component, and mark the Scrollable property as "True", then in run time, the component simply "forgets" that the Scrollable property was marked as true.
The workaround is very simple. To make the TreeView "Scrollable", you must actually add a line of code to make it scrollable, because unfortunately the "bug" in this component is that it forgets.
For example, you must simply add in code something like this
tvTreeView.Scrollable = true;
This workaround fixes the problem, and the tree view will then properly display its Scroll bar(s).
I was wondering... I have a WinForms System.Windows.Forms.ListView with a bunch of ListViewItems that I'm drawing using the View.List style. Each ListViewItem has a "SmallIcon" that I fetch from the ListView's SmallImageList.
My problem is that the icons are showing too close to the border on the left. I've tried to change the bounds and the ListViewItem's Position property to no avail.
Is there anyway to have some kind of offset to ListViewItems?
The Win32 listview control doesn't have any setting to increase the space between the icon and the label (in any view, not just List). Setting ListViewItem.Position does nothing when the ListView is in List view.
A low-tech solution would be to simply prefix every ListViewItem's Text value with a single space. Slightly ugly, but oh so easy to do.
If you really want to have pixel level control, you will have to owner draw it. As always, if you are doing anything with a .NET ListView, ObjectListView makes owner drawing your items trivial.
As mentioned already, prefixing the text of all your items with a space is a super simple way to add padding. This has a pretty significant drawback, however. Once you do this, you lose the ability to find items in the ListView by simply starting to type their name while the ListView has focus.
Try adding white space to the left of your small images.
If you're using 16x16 images change to 24x16 for example by adding 8 white (or ListView Background color) pixels to the left.
If you are in ListView View LargeIcons then you can postion the text using item.position
A screenshot would be nice for an example to see exactly what you're after.
Funny thing... the Windows Explorer uses the ListView to display files and folders. i usually run my view in Report or Detail mode. i just switched it to List view mode and see the exact problem that you're describing! Yikes. Might be a bug with the Win32 object and that particular view type!
A quick workaround might be to use a Report style for the ListView with a single column or perhaps implement something yourself. The FlowLayoutPanel in .Net would work very nicely as a starting point for a custom list view.
As you are using the View.List style, I suspect you'll either need to implement some custom drawing or consider padding your images. You could also look at overriding the ListView control and manipulating it's bounds by overriding SetBoundsCore or SetClientSizeCore (or similar).
However, if the ListView were set-up for View.Details view, this could be done using the ListViewItem.IndentCount property:
The IndentCount property can be used
only when the View property of the
containing ListView is set to Details,
and the SmallImageList property of the
ListView is set. Source:MSDN
If you set the StateImageList property you can add a space of 16 px before the icons. I think you can adjust this additional space by loading an image with matching width as first entry into the StateImageList. But I have not tested this.
This thread discusses the opposite problem.