Windows phone - stretch image - c#

I want to stretch the image on the whole page.
Fill is not appropriate - the proportions are not saved.
UniformToFill - leaves an empty space above and below.
I need to image spread over the whole page to the conservation scale.Part of the image will be clipped. How do I do this?

Both UniformToFill and Fill take the whole available space, but with different stretching behaviours. If you see empty space, that means that not the whole space is available. Maybe you placed Margins or set explicit Width and Height on Image (or placed the Image in a container with Margins or Width/Height).

Related

Render an image and overlaid controls in exact pixels?

I have a background image that consists of an outline, with 10 rectangles placed specifically on the outline. I want to display that image on the screen, and overlay transparent buttons that match up to the rectangles on the image. When the button is pressed, the button's outline will turn to orange to indicate the rectangle has been selected.
I'm finding that simply setting the width and height of the buttons to match the pixel width and height of the rectangles in the image always renders a button much larger than the corresponding rectangle.
The image itself is 669 x 871px, and the rectangles are all 87 x 143px. Setting the Image's WidthRequest and HeightRequest in code or in XAML seems to render it at a different resolution than it actually is, thereby leading to the issue I described - if a button's size is set to 87 x 143 (again using HeightRequest and WidthRequest) it always renders larger than the rectangle.
Furthermore, if I contain the buttons in a StackLayout (as I often need to do) and specify a margin to push the layout downwards to align with the rectangles on the image, again the correct number of pixels never matches up with the distance the layout is moved.
I'm aware of how to overlay elements using a Grid with a single row and column and simply defining multiple layouts in the same space and triggering visibility in code. What I don't know how to do is display the elements in exactly the right pixel sizes that I need for the controls to always align with the image.
The diagram I'm working with:
Desired behaviour:
Actual behaviour:
I've worked out how to do this by using Grids within a Grid. By setting the Grid's row and column height and width to "*" (use all available space), defining a ContentView containing the diagram, then several smaller grids to lay over the top with their row height and column width matching the dimensions of the diagram image (i.e. if the image is 600 pixels wide, the nested Grid's ColumnDefinition's Width="600"),
I was then able to define the buttons inside a StackLayout, inside the nested Grids. I've tried this out across a few different resolutions and it seems to work just fine for my purposes.
I had to set Padding to 0, and used the Margin to vertically align the StackLayout as needed (i.e. for the first row of buttons at the top of the diagram, their StackLayout's Margin was "19,89,19,0" - 19 pixels from either side, 89 pixels from the top).

Unity List view which stretches to fill remaining space available screen space

I'm trying to make a file browser control for unity. Everything works fine when I'm using my standard resolution.
However when I Change resolutions the inner box is not flexable. so the scroll bar and list view will overlap the bottom footer or leave too much space
My header is a fixed height of 150 and my footer controls is a fixed height of 280. Honestly I'd preffer If I could figure out a way to make those not fixed as well. So that they would take up top 10% of screen and bottom 18% of screen
The inner list view box should expand to consume the remaining space.
I know I could write a script to do all of this but with the new UI I'm almost sure there is a way to do it with the built in components.
Does anyone know how I can make my Panels and all of its children act as a flex box?

scale and draw image inside a lager canvas

Hi I'm hoping someone can help point me in the right direction to how i might go about solving this issue.
I have a blank image (white) which is 3000x1500 which acts a a canvas, i then have an image which again could be any size and any orientation. What i need to do is scale this image to fit inside the blank white canvas as best as possible and also center it. I would expect to see white gaps at the top or bottom of the final image if the image could not be scaled to fix the exact canvas.
Can anyone suggest what i should research, how i would go about drawing an image inside another in C# WPF and anything that may already exist that i could use to achieve this.
I forgot to mention that this would need to output to a bitmap so it could be saved to disk
All you need to do is to put an Image control into an appropriately sized Grid with white background, and set its Stretch property to Uniform. No Viewbox required.
<Grid Width="3000" Height="1500" Background="White">
<Image Source="<path to image file>" Stretch="Uniform"/>
</Grid>
Look up ViewBox. A ViewBox automatically scales its single child element based off of the stretch parameter.

Dynamic Re-size a Canvas box to match an image box

I must create an application that requires me to have an image inside of an image box and I must draw on top of the image in a canvas box that is to be placed directly on top. I can't place the image inside the canvas box as I need the image to stay it's original size. Is it possible to have the canvas box match the image box as it changes sizes and move to the proper place directly on top of the image box?
As Rachel put it: "A Canvas does not adjust the size of it's children like many other WPF panels do, so you are safe to place the ImageBox inside of the Canvas, and it will keep it's original size."

Drawing ListViewItem exceed VisibleClipBounds

I'm trying to manually draw ListViewItems on a Custom UserControl. The control itself is a wrapper around a ListView stored as a private member on the class.
There is a DrawListViewItemEventHandler attached to allow manual drawing for these items, and for the most part this seems to work. The problem I have is where the text for the ListViewItem (in large image mode) is long.
I'm drawing a bounding rectangle around the ListViewItem with various themes, and I then measure the size of the text using Graphics.MeasureString() and manually draw the text. However what I'm finding is that the vertical drawing is cropping at 2.5 lines of text, because the caption is falling outside of the VisibleClipBounds of the graphics context I have been passed.
It seems a bit of a strange but I'm not sure why such a thing should happen and can't figure out how to get around the problem.
You could use Tile view and TileSize to give yourself enough space to draw your text.
The ListView can't guarantee to draw all its text: the text could be huge.

Categories