Silverlight Scrollable Content Problem - c#

I am fairy new to Silverlight and I have a problem.
I have a grid on a page that is resizable when the user resizes their browser window.
In one of the grids columns I want to display dynamically added content that is scrollable, as there is more data than space available. I currently have a scrollViewer with a stack panel inside it, that i programmatically add a user control to and then several user controls to that control depending on the amount of content.
My problem is this. The scrollViewer does not respect the available space and as such displays its content outside of the viewable area when there is more data than space. i.e. it does not uses it is not scrollable nature.
Hopefully this is something simple that I have missed, but i am banging my head against the wall at the moment. Any help gratefully received.

With seeing the xaml, my guess is that the problem may be with the StackPanel. StackPanels don't display scrollbars when their content is too large. I would suggest adding your UserControl directly inside of your ScrollViewer. If your ScrollViewer needs to have multiple children, I would suggest using a different type of container such as a Grid or a ListBox.

Related

How can I create a usercontrol with a panel that slides down over it's parent control?

I want to create a UserControl that displays a dropdown selection control and a couple of buttons when collapsed, but could be expanded to display a larger selection of items when desired. It's expansion panel should slide down over the controls of the Window or UserControl it's embedded in.
I can do it if all of the XAML is in the same control, but I can't figure out how to do it if I want the small view and sliding bits in a separate, re-usable, UserControl.
For a small panel I am using an animation that changes the margin of an offscreen panel and bounds clipping to make it happen. I have been copying the XAML from Window to Window. I want to make a re-usable much larger version of this, but displaying it, properly, has me a bit lost because of the bounds clipping. The UserControl clips the panel within it's smaller view, rather than allowing the panel to display over it's parent.
This is the effect I am looking for:
The primary issue seems to be that the sliding panel has to be contained within the UserControl, or it gets cut off. So the user control has to be much larger than its collapsed view. Because of that, when you want to embed it in another Window (or UserControl) you have to do XAML gymnastics to accommodate for the size of the control while making appear that the control isn't really that big.
Maybe that's just typical for XAML. I am still learning. But I can't figure out how to have a visual element of a control appear outside its bounds. A Popup doesn't really work because of how it opens and closes with focus.
At this point it's just an exercise, as I've decided to implement it a different way (modal dialog) so I have the control I need over the visuals.

Silverlight auto height problems with nested controls

I've inherited a silverlight app that now needs extending. The app sits on a map and originally had 1 text block item and a single accordion control of options. This has been extended so that the text block becomes an accordion item and further accordion item has been added with 2 sets of controls.
So my plan started along the lines of
<accordionMain>
<accordionMainItem1>
<accordion1>
<accordion1Item>
<controls>
</accordion1Item>
<accordion1Item2>
<controls>
</accordion1Item2>
</accordion1>
<accordionMainItem1>
<accordionMainItem2>
<accordion2>
<accordion2Item>
<controls>
</accordion2Item>
<accordion2Item2>
<controls>
</accordion2Item2>
</accordion2>
<accordionMainItem2>
</accordionMain>
This would hopefully give me the structure that I needed to add controls to.
Being new to Silverlight but having done a bit of XAML I made some progress but have hit a problem.
The StackPanel and Canvas that the whole thing sits on does not resize automatically as I would like. I'm unsure how to go about this but have tried Height="Auto" with no luck. What I would like would be when the 2nd accordion is expanded the panel and border underneath auto size as needed.
I have attached the full XAML here
Personally, I avoid the StackPanel for non-trivial layout of controls. I find a Grid is much more flexible when it comes to filling available space and resizing, which is normally what I want when designing an interface that will grow and shrink.
So my first step with your example would be to define a couple of rows for your grid, and place your expanding elements into a row each. Looking back at your example I see there is actually only one expanding thing: the AccordianMain, so make sure that is in a Row where Height="Auto".
What are you using the Canvas for incidentally? And why is the Grid that contains the accordians on the Canvas, and the only item in the StackPanel the Canvas?
Try and simplify your layout, I don't see why your inner Grid can't be directly placed into your Border and so can't see what the StackPanel or Canvas are bringing to the party. But maybe I'm missing something.

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

How not to resize a datagrid or a wrappanel item?

I have created a user control in which I have a datagrid along with other items.
One of the functionalities of these control is that through two buttons I can add or remove columns from the DataGrid.
Multiple of these controls are placed inside a WrapPanel, to display in my main application.
Now while running my application and I press the button to add a new column to the datagrid, the datagrid changes size and as result the initial user control becomes wider, which means that one of the childs of the wrappanel is wider than the other ones.
If I add multiple new lines and the user control reach the width of the application window then a scrollbar apprears below the datagrid so I can scroll and see all the contents in the datagrid.
Is there any way to prevent this behaviour?
Ideally I am looking for my wrappanel child to have a constant size, and my datagrid directly to present the scrollbar upon addition of a new column in it. Thus all the wrappanel childs have the same width.
I dont want to place a specific constant size to my user control if that is possible.
It is possible to achieve the same result with a Grid than with a WrapPanel, just a little bit less handy.
Starting from a grid you can set Width/MinWidth/MaxWidth (with star notation) and Height/.../... to get the behaviour you want.

Custom Items in Lists in C# forms?

I'm a bit new to the C#-form app developing and I want know, what's the best way around at making a control that holds a list of horizontal items. In which each of these items are horizontally ruled to it's parent control, contain a thumbnail to the left and a large text block to the right of image and a smaller text block underneath that. So basically this isn't a predefined control I can find in the toolbox. Any ideas?
You could lay this out with Panels in form controls, or with WrapPanel and StackPanel in WPF.
In WindowsForms, I would create a user control that held the correct layout for a single item, then make a list of them at run time.
In WPF I would use a List control, but set the layout template to use WrapPanels and StackPanels.
WPf is the better solution long term if you don't have to coexist with winforms

Categories