For a Windows 8 Metro app, I have a Rectangle inside of a Canvas inside of the main Grid, such that:
<Grid>
...
<Canvas>
<Rectangle />
...
</Canvas>
</Grid>
How would I make the rectangle dynamically take up the width of the screen?
Canvas does not constrain or change its children's size or positions. If you want your rectangle to be as long as the screen width I recommend to put it inside the Grid, as the Grid has the size you need for the Rectangle (with HorizontalAlignment="Strech"). Or you might bind Rectangle.Width to Grid.ActualWidth.
Related
Is it good to use margin/padding to align the position of CachedImage in XAML Xamarin Forms? Or any other preferable/good way to align it so that it can stay consistant to all devices screens?
Like for example:
There are plenty of options, which to use will depend on the rest of your layout. Anyway, increasing the transparent area of the image will not port very well, because of different screen-sizes and -ratios.
Learn about layouts in Xamarin.Forms, it will help you much. On way to center (or otherways align) an image would be to use an AbsoluteLayout (see here)
<AbsoluteLayout HorizontalOptions="Fill" VerticalOptions="Fill">
<Image Source="whatever.png"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds=".5,.5,-1,-1" />
</AbsoluteLayout>
AbsoluteLayout.LayoutBounds=".5,.5,-1,-1" sets the position of the Image to centered, while the size is retained.
I have write a simple code in XAML for zoom an Image
<Grid Grid.Row="1" Background="AliceBlue" Margin="10,10,10,10" Name="Griglia_Immagine">
<ScrollViewer Name="MyScrollViewer" MinZoomFactor="1" ZoomMode="Enabled">
<Image Name="Imm_Visualizzata" Source="Assets/Test.jpg" >
</ScrollViewer>
</Grid>
When i zoom the image it became more big.
On my right i can see the vertical scrool bar but i don't see the Horizontal one.
So... where the image is big i can move Up-Down ...but if i move left-right the image where i leave my finger the image return on left border.
I'had tried to set HorizontalScrollBarVisibility and VerticalScrollBarVisibility ...
If i set both to Hidden the start image is very big (original format) If i set both to Disabled the zoom not work.
If i set One on Hidden and one on Disabled the zomm work but i can move the image only vertival or horizontal... where i had set the Hidden value..
Anyone had solved it ?
Thanks
Background
I'm a noob on Windows Phone 8. I've learnt WPF and Silverlight in the past, but it was long ago.
On Windows phone 8, I have a clickable Image control which I wish to have its content (the picture itself) to have rounded corners.
The question
How do I set rounded corners to a control?
Also, I might consider having a Button control instead, so that I could customize what happens when it is being clicked (or touched). Upon clicking, I would like that the area that has the rounded corners would be colored in some color, showing that it was indeed being clicked/touched. How do I do that?
EDIT:
Thanks to #Depechie, I've found this solution:
<Grid>
<Border Height="200" Width="250" CornerRadius="0,0,50,50">
<Border.Background>
<ImageBrush ImageSource="Images/Desert.jpg" />
</Border.Background>
</Border>
</Grid>
However, I have two problems with that:
I still can't find how to make it seen as clicked when you touch it, so that the rounded corners would have a yellow background.
I can't get the imageSource and the converter (and its parameter) via code when handling the clicking event. Previously, I've used:
Image thumbnailImage = (Image)sender;
var bindingExpression = thumbnailImage.GetBindingExpression(Image.SourceProperty);
string selectedItem = (string)bindingExpression.DataItem;
string selectedThumbnailIndex = (string) bindingExpression.ParentBinding. ConverterParameter;
Maybe I could create the items programmatically instead of Xaml? If so, how (items are in a grid, btw)?
What can I do now?
Try this by using Rect
<Image VerticalAlignment="Center"
HorizontalAlignment="Center"
Stretch="None"
Source="Jellyfish.jpg">
<Image.Clip>
<RectangleGeometry RadiusX="5"
RadiusY="5"
Rect="0,0,150,113"/>
</Image.Clip>
</Image>
Here is the another link
https://msdn.microsoft.com/en-us/library/ms750631(v=vs.110).aspx
There is a similar question listed here...
Maybe those can help you too?
And if you want to have the ilusion that the image is a clickable control, take a look at TiltEffect that is available in the Phone toolkit
Instead of attempting to alter the shape of a control (Which after looking in VS and Blend I dont think is possible) Why not simply create your image with rounded edges and then set the button border and background to no color?
For the rounded corners, you can set the RadiusX and RadiusY values to nonzero numbers to achieve that effect in a rectangle. So I imagine you could embed a button inside the rectangle if you want to keep the button control.
<Image Width="25" Height="25" VerticalAlignment="Center"
HorizontalAlignment="Center"
Stretch="Fill"
>
<Image.Clip>
<RectangleGeometry RadiusX="12.5"
RadiusY="12.5"
Rect="0,0,25,25"/>
</Image.Clip>
</Image>
The corner radius should be half of width or height.
I have a main page with 2 canvas like this:
<Canvas Name="main_canvas_color" Width="480" Height="800" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center">
<Canvas Name="main_canvas_image" Width="480" Height="800" HorizontalAlignment="Center" VerticalAlignment="Center">
</Canvas>
</Canvas>
the first one is filled by color the other one is filled by image. In PhoneApplicationPage_OrientationChanged event a swap width and height for both canvas. If i rotate a screen, it works fine, everything positioned correctly. If I add a Border element as a children to main_canvas_image and then rotate screen, main_canvas_image is not updated in a right way, it is shifted toward top right corner. If I open any another page and then go back after that, main_canvas_image is updated properly. So it seems that i have to force layout update, but i don't know how to do that. I tried UpdateLayout(); inside PhoneApplicationPage_OrientationChanged event, but it does not work. How can I update canvas layout in a right way?
Why bother ? The phone automatically adjust the size when you change the orientation. No reason to write code for it yourself.
I have an image as a drawing brush in xaml. The only property set is Stretch, which is set to Uniform.
The image is then set to the background of a usercontrol which has no properties set with regards to size.
The usercontrol is then used within a a grid, and set to span 2 rows like so:
<common:Logo
Height="130"
Width="500"
Grid.Column="0"
Grid.Row="0"
Grid.RowSpan="2"
HorizontalAlignment="Left"
/>
The problem is that there is loads of white space on top and below the image, which is also quite small.
The image started as a vector graphic and has no space above or below.
When I view the usercontrol with sizes set, it fits perfectly with no white space.
I am hoping this is not a problem with the grid reporting an incorrect size.
Any ideas would be appreciated!
Visual Studio was not refreshing any of the changes, running the code and reviewing what was produced fixed the whole problem!