GridSplitter like for listview: Is there any such control? - c#

I have a listview that I want to give the user the chance to resize the height of items similar to a gridsplitter. Is there any such control for this purpose?
I am using wpf and .net 4.5, c#

What you can do is use a canvas with two listviews, and then use a thumb control to allow you to resize those listviews.
Thumb control: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.thumb(v=vs.110).aspx

The quickest way is to use DataGrid and set its RowHeaderWidth to the desired value to make the splitter area more visible to user.

Related

How do I change a VirtualizingStackPanel's orientation in code behind?

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

Resizing SplitContainer makes controls invisible

Why does the WinForms SplitContainer hide all the Buttons in a Panel (in the left Splitter) when I resize on of its panels? Do I have to write specific code for invalidation of the Panel?
Yes, there's a solution. You can use Anchor property of SplitContainer in winforms. Using which you can set the value of the anchor as you required.
EDIT:
Anchor property will make your control fixed to the winforms design. Even if you resize the control, all the controls that the major control is holding will also resize according to it.

Place control over other

I am searching a way to put a ComboBox over another Control with xaml. The new combobox should aligned on the right side of the window.
How can I do this?
Best Regards, Thomas
You can use Grid panel. If you do not specify Row/Column of the controls inside the Grid, they will overlap.
Another solution is to use Canvas layout, which is almost like what you have on WinForms, where you can set X/Y of the control and you have more control on where they should appear.

How do I make multiple controls in a Windows Form automatically resize with the window?

I'm new to Windows Forms in Visual Studio, and I am wondering how to automaticly resize controls to the window size.
Say, I have 2 controls in a panel, a List Box and a Button. I want the button to dock to the bottom, and I want the List Box to fit the rest of the space. when the window resizes, the button should be at the bottom (as expected with docking), and the list box should stretch down to the button.
Is there a way to do this without any code?
Thanks.
Dock is pretty easy to use, but I recommend using the Anchor properties instead. Resize your form to a reasonable size in the Designer. Then, place your controls to look the way you want. Then, decide which controls should resize with the form and set the Anchor property as follows:
If you want the control to resize with the form in width, set the Right anchor.
If you want to resize height, set the Bottom anchor.
If you want the control to stay right when the form resizes, unset the Left anchor.
If you want the control to stay bottom when the form resizes, unset the Top anchor.
The problem I have with Docks is that they sometimes act funny when controls are not declared in a specific order, and to get the effect you want, sometimes you have to create extraneous panels just to hold controls.
It really gets messy when you want to maintain the aspect ratio of each control. One way, which is not really up to the mark if you want to get into fixing the details, is to use TableLayoutPanel and use Dock and Anchor wisely to achieve what you want.
Use the dock and fill options on the controls. Look under properties for each object, and containers if they are in any.
You can use SplitContainer
Google for examples. Here is one
Try setting your ListBox's Dock property to Fill.
You'll need to watch for one thing though: by default the ListBox will size itself to display whole list items. If you resize the control so that it displays a partial item it will adjust itself so it will display a complete item. This can make the control appear to lose its 'Dock'ing behavior. The solution for this is to set the ListBox's IntegralHeight property to false, which specifies that the control not resize itself to fit complete items.

Resize ElementHost to size of the hosted XAML UserControl

I would like an expanding panel in my Windows Forms app. I was having a look to see if this would be possible using the WPF Expander control. I've created a Xaml UserControl where I've inherited from Expander rather than UserControl. I have a trigger on the Expander for setting it's size.
Is it possible to change the height of the ElementHost to reflect the change in the size of the child? Or would I just be better off creating an expanding Panel in Windows Forms?
I'm using C# .Net 3.5.
Cheers
Yes. You need to override MeasureOverride in your outermost WPF control, convert the size from WPF coordinates to device coordinates, and update ElementHost.Size.
Since you are already subclassing Expander:
Override the MeasureOverride method
After the measurement is calculated, use PresentationSource.From(visual).CompositionTarget.TransformToDevice.Transform(point) to get the device coordinates
Update ElementHost.Size.
Your Expander subclass instance will need a pointer to ElementHost to do this.
A more general solution would be to create a new class to handle the synchronization. It would subclass FrameworkElement and be the direct child of ElementHost.
Is there any particular reason you are inheriting from Expander vs. just using an Expander in your UI?
If you set up the H/V Alignment properties of the Expander, you should be able to get most standard sizing behaviors without having size triggers. From my experience, the content portion of the Expander automatically sizes to fit.
If you're trying to completely remove the header part, then you might look at making your own ControlTemplate for the Expander.

Categories