Resize Silverlight application to fit window - silverlight

I have created a silverlight application that has been placed on an entity form and currently it has been set to a fixed width. What i'm after is for the application, including the datagrid and pagers that are in it, to stretch to the width of the window.
So far i've been unable to find anything that works so I was hoping that someone would be able to help me with it?
Thanks

You Should Try To Column width And Row Hight "Auto" And Also You Should Try StackPanal To Fix This Problem

Try use Stackpanel in your silverlight page and place all of controls in stackpanel and set it's width to "Auto".

Related

image gallery with scrollviewer - wrap panel does not respect boundaries of scroll viewer

I'm trying to create a gallery-style layout with a ScrollViewer and a WrapPanel in WPF, but the WrapPanel is extending beyond the boundaries of the ScrollViewer. I've tried setting the HorizontalAlignment and VerticalAlignment properties of the WrapPanel to "Left" and "Top" respectively, but it still doesn't stay within the boundaries of the ScrollViewer.
I've also tried setting the height of the WrapPanel to specific values and set the MaxHeight properties of the WrapPanel to limit the size, but it still doesn't stay within the boundaries of the ScrollViewer, and is no longer scrollable. I've also tried wrapping the WrapPanel inside a Grid and set the height of the Grid to the size I want and set the ClipToBounds property of the Grid as "True", but it still doesn't work.
I'm not sure what else I can do to keep the WrapPanel within the boundaries of the ScrollViewer. Can anyone help me figure out how to contain the WrapPanel within the ScrollViewer?
This is my xaml code:
<ScrollViewer Grid.Row="0">
<WrapPanel x:Name="Preview_WrapPanel"></WrapPanel>
</ScrollViewer>
and this is my result in my app, in the beginning, the distance from top is correct but the bottom not. I scrolled a little up to show that the height is not respected in the top region as well:
the width is respected, but i think only because this is the application width.
The thick red border is the area, which the scrollviewer occupies. The wrappanel should be contained inside, kind of like a window, where you can only see whats behind the window and not the trees behind the wall.
the wrappanel gets filled with WebView2 Media, each image around 200x200px:
WebView2 media = new WebView2();
media.Source = new Uri(nftFile.FullName);
media.Width = 200;
media.Height = 200;
this.Preview_WrapPanel.Children.Add(media);
I use Webview2 because the content could pretty much be anything, image, video, pdf, whatever. Also it supports webp
For now though, im only adding images.
There was a known bug with webview2 and it seems it has not been fixed.
Basically, renders on top so cannot be clipped.
https://github.com/MicrosoftEdge/WebView2Feedback/issues/2579
https://github.com/MicrosoftEdge/WebView2Feedback/issues/286
You need a different plan.
Maybe ensure it doesn't matter when they don't clip.
Maybe use images.
Or hope it gets fixed soon.
Andy was correct, this is a known issue. Microsoft knows about it since .net framework Times (>10 years) but refuses to fix the issue so far.
I solved the issue by Installing the Nuget Package CefSharp which uses the chromium engine as well.
What a pitty.

silverlight scrollviewer height and width setup

I am having problem understanding the scrollviewer in silverlight webpage. There are the usercontrol and grid "layoutRoot". My scrollviewer is set before the "Layoutroot" grid. It never worked properly. Even though I have other items at the bottom of the page, I could not scroll to them and could not see them. I have been playing with UserControl MinHeight, DesignHeight and minHeight of both LayoutRoot and Scrollviwer. Just have a hard time figuring out what is the best way to set it up.....
You need to remove min height and max heigh from all of the control because Silverlight takes care of all those things. What you need is to set VerticalScrollBarVisiblity to auto. By default it is disabled and you will be able to achieve what you want.
Cheers!
Vinod
If the MinHeight properties are set too large then it will not be viewable on the screen and will be cut off. If you remove the MinHeight properties on both the UserControl and ScrollViewer then it should work fine.
Or if that doesn't work post your code so we can have a look.

Silverlight DataGrid vertical scrollbar issue

I have a DataGrid in my silverlight application and I'm wondering how to get the same behavior for the vertical scrolling as the horizontal scrolling. When I resize the browser horizontally, The app will bunch up all the controls and the horizontal scrollbar will appear, however when I resize it vertially, the controls at the bottom of the app just move out of view. Does anyone know any tricks to handle something like this?
My problem is StackPanels. Don't use them, they are evil and don't resize.
I couldn't get the scrollbar to show up at all with the datagrid. Removing the datagrid from a stackpanel and using a grid instead also solved my problem.
Good call!
In my case the Height of the rowdefinition where I have the datagrid was set to "Auto" and it had a rowdefinition below with height set to *. I switched the values and it worked.
Yes stack panels causes some unknown errors in Silverlight, I Had also experienced problems with regards to stack panels like nesting data fields inside stack panels which are also inside data forms.

Why is DataGrid "Auto" width so huge all the sudden?

I have been working on an app with a datagrid from the wpf toolkit and the width was not specified in the xaml (default to auto), and it was working fine. It would extend the window width as I resized the window. However, all the sudden the "auto" width is massive and I don't know why. When I pull the xaml file up in blend it shows auto width is 50002 pixels. I barely touched anything else in my xaml since it happened. Anyone know why it is doing this and where that number came from? Thanks
The most common cause for this that I've seen is when the control is inside a StackPanel with Orientation=Horizontal. StackPanels don't constrain their controls in the stacking direction so if nothing else constrains the control it grows to some maximum size.
If this is the issue try replacing your StackPanel with an equivalent DockPanel or Grid.
If you were doing any manual resizing using the Visual Studio IDE then perhaps this could have happened or you could have accidently typed in the wrong size of 50002. Removing the widths and setting to auto should fix the issue.

Is there a way to automagically make a canvas scroll on overflow in WPF?

Been checking the web and this site, but couldn't come up with any descent results.
Is there a way to make a canvas in WPF show scrollbars on overflow ? Been trying the scrollviewer, but can't get it to work :(
Thanks in advance..
The problem you're running into is that Canvas, unlike many WPF panels and containers, does not size to contents. That means if you add an element which goes outside the canvas boundaries it will not update it's size. Hence embedding a Canvas in a ScrollViewer will do no good unless you manually update the size of the Canvas.
It sounds like what you want is a Canvas which supports size to contents. This blog entry has exactly that control.
http://themechanicalbride.blogspot.com/2008/11/auto-sizing-canvas-for-silverlight-and.html
I took a different approach and abandoned the Canvas for Grid. The Canvas is more performant but for my purposes at least I haven't noticed a difference. The grid can mimic the behavior of canvas by doing the following.
Create a single row,single column grid.
Set the HorizontalAlignment to Left
Set the VerticalAlignment to Top
Use Margin "x,y,0,0" to set the position.
Bam..works just like canvas and it works great in a Scrollviewer.

Resources