In my Xamarin forms application I want to add borders to a Grid / StackPanel. Also the background color will be transparent. I used frame control , but when I set background color to transparent the border also not shown. Please help me?
You basically have two possibilies, since this is not yet supported in Forms, where the first is to use BoxViews as explained on SO in this post.
Otherwise, you can wrap a StackLayout around your View (the StackLayout or Grid as you mentioned) with a BackgroundColor and Padding of 0.5 as explained here.
Let me know if you need more concrete examples.
There's no Border property for GridView, but:
Just set grid.BackgroundColor to your desired border color value, then set grid.ColumnSpacing and grid.RowSpacing to some value and make sure all controls you add to the grid have own BackgroundColor set correctly.
A BoxView can be used for border purpose. In the following XAML code, note that FillAndExpand option is used for HorizontalOptions of the StackLayout
<StackLayout VerticalOptions="Start" HorizontalOptions="FillAndExpand" >
<BoxView BackgroundColor="Cyan" HeightRequest="5" VerticalOptions="End" HorizontalOptions="FillAndExpand" />
<BoxView BackgroundColor="Cyan" HeightRequest="1" VerticalOptions="Start" HorizontalOptions="FillAndExpand" />
</StackLayout>
There's no Border property for GridView, but:
Just set grid.BackgroundColor to your desired border color value, then set
grid.ColumnSpacing and grid.RowSpacing to some value and make sure all controls you add
to the grid have own BackgroundColor set correctly.
You also have to set Grid.Padding to whatever the border width you want.
Related
I have a grid with Frame elements as cells. Within some frame elements, there's label elements. The problem is the label stretches only as much as its content.
My goal is to make labels take the entire space of its parent elements(Frames).
I tried setting the VerticalOptions and HorizontalOptions properties to "StartAndExpand" and also "FillAndExpand" to no avail
<Grid>
<Frame Grid.Row="0" Grid.Column="0">
<Label Text="Hello" />
</Frame>
...
</Grid>
Thank you!
EDIT: To clarify, I want to stretch label itself but not its text.
As Frame has a default padding, simply set it manually like below.
<Frame padding="0">
<....>
</Frame>
Plus, sometimes label with long text not behave correctly inside the Frame,
and one workaround is to wrap the Label with a StackLayout.
I am trying to create a simple stacklayout UI.
Here is the XAML.
<ContentView>
<StackLayout
BackgroundColor="Green"
HeightRequest="500"
VerticalOptions="End">
<StackLayout
BackgroundColor="LightSkyBlue"
HeightRequest="100"
VerticalOptions="End">
<!-- // ADD CONTROLS HERE[! -->
</StackLayout>
</StackLayout>
</ContentView>
Ideally it is expected that the 'blue' stacklayout should align itself at the bottom on the green one But, it just doesn't moves and stays on the top.
What am i doing wrong?
Please point me in the right direction
Attaching the image for better clarity.
You just need to replace your code by below code:
<StackLayout
BackgroundColor="Green"
HeightRequest="500"
VerticalOptions="End">
<StackLayout
BackgroundColor="LightSkyBlue"
HeightRequest="100"
VerticalOptions="EndAndExpand">
<!-- // ADD CONTROLS HERE[! -->
</StackLayout>
</StackLayout>
Hope it will help you
Thank you
In my experience, a StackLayout will never obey Vertical or Horizontal options. It will only use as much space as it needs. You can place a transparent BoxView in the StackLayout and set its VerticalOptions to FillAndExpand. That will force the StackLayout to use all the space.
I normally use a Grid instead and use <RowDefinition Height="*"/> to force it to use all the space.
You need to set blue Stack Layout's Vertical Option to EndAndExpand. Because stack layout children doesn't fill automatically. You need to force it if you want. You can look at this answer here for detailed explanation.
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.
how I can apply color adjustment to an image in windows phone. Is there any free sdk is available that support color adjustment. In my application I need to apply a color shade to an image based on the color he selected from color pellet. Can anyone please help me to implement such functionality in windows phone.
Place a rectangle over the Image and set its opacity to 60%. (It is easier if you use Expression Blend for this part).
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Margin="188,208,168,299" Source="wifi-signal.jpg"/>
<Rectangle Name="Rect1" Fill="Blue" Margin="188,208,167,299" Stroke="Black" Opacity="0.595"/>
</Grid>
In the Code View, you can trigger an event, to change the color of the Rectangle using the following code:
Rect1.Fill = new SolidColorBrush(Colors.Red);
Here is a simple XAML snippet:
<Grid x:Name="ContentGrid">
<ContentControl Background="Yellow" VerticalAlignment="Stretch"></ContentControl>
</Grid>
In WPF, the content control stretches the entire height of the grid.
In WP7 however, the content control does not stretch.
Why?
Avoid using ContentControl directly.
If you use something which inherits from it, such as a button, then, in a grid, as per your example, you'll automatically get horizontal and vertical stretching.
This will creat a button with a yellow background which fills the screen:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Background="Yellow" />
</Grid>
However, if you just wanted a yellow background to your grid - which is all your sample would do - you could just set the background property on the grid itself.
I fixed this by defining my own template:
<ContentControl><ContentControl.Template><ControlTemplate><ContentPresenter/> ...
Not sure why it fixes it but it works....