Xamarin forms get font size setting - xamarin

Can I get this font size setting in my main Xamarin project. I like to set this RowHeight value for just the Android's.
xaml
<Grid.RowDefinitions>
<RowDefinition Height="{Binding RowHeight}"></RowDefinition>
</Grid.RowDefinitions>

So you can, you need to account for the platform variations by using the
Device.GetNamedSize
method, which takes a NamedSize enum to designate the font size, and then the type which could be label, or other view that could be handled. So if you want to base this off of a label with medium size, run:
RowHeight = Device.GetNamedSize(NamedSize.Medium, typeof(Label))
+ (consider adding some padding to account for margin etc here);
https://learn.microsoft.com/en-us/dotnet/api/Xamarin.Forms.NamedSize?view=xamarin-forms

Related

Xamarin Forms Controls with borders

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.

How to display images of different height in listview on Windows Phone 8

Does anyone know how to develop something like this on Windows Phone 8?
http://sdrv.ms/17PUTs4 "Snapshot of an existing app"
I know I can use WrapPanel to get multi-column list view but I don't know how could I get different height for each list view item
I see that listBox in sample app is divided into 3 columns - it's easy to do.
Next:
Each column should be filled with imagecontainers with HorizontalAligment="stretch" to get columns width, images Height set to auto so that with resizing the width the height would be set automaticaly so that there were no unproportional resizes. And image Stretch property to Uniform.
Something like:
<Image Name="BackButton" Source="BackButton.png" HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" Width="auto"/>
Addition:
To get that kind of list box, i suggest you using MS ExpressionBlend to make custom user control

Wpf controls size is coming small/blurry in wpf ViewBox

I have an usercontrol in wpf window. In usercontrol, I have put all the controls inside the viewbox so that if the user resize the window it does not effect the scaling of the usercontrol.
<Viewbox >
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
---------------------------
---------------------------
</Grid>
</Viewbox>
In the first image, when the window is not maximized the usercontrols controls are coming as below i.e. small and blurry. Size of the controls are not constant.
if the user maximized the window, the usercontrol is coming fine as below:
Kindly suggest how to solve this issue?
Thanks
Check this out:
TextBlock inside a Viewbox - strange rendering
And try playing with TextOptions.TextFormattingMode values on Viewbox (assuming the controls n the screenshot are rendered as text with fonts, not bitmapimages.

Applying color adjustments to an image

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);

Align TextBlocks by baseline

I have two TextBlocks, each with a different font size, and am trying to align them vertically so that their baselines match up.
I know how to do this by creating multiple Run elements within a single TextBlock, but in this case my TextBlocks are not directly adjacent, so that won't work. Here's a simplified example of my layout:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0"
FontSize="20"
VerticalAlignment="Bottom">Small</TextBlock>
<TextBlock Grid.Column="1"
FontSize="50"
VerticalAlignment="Bottom">Large</TextBlock>
</Grid>
If I could find a way to calculate the baseline of the font in code, that would be good enough - I could do the alignment in code, using a Canvas or custom Panel - but I haven't been able to find any WP7 APIs for finding font metrics.
I have found a very similar question here, but the solution involves the FormattedText class, and unfortunately this is not available on WP7.
I would really like to be able to do this without hardcoding any margins/offsets, if possible.
Whilst I agree with Matt's answer, if you actually need to solve the problem without manually setting margins, etc, then you can align them "properly" by setting the LineHeight to the tallest line, and then setting LineStackingStrategy to BlockLineHeight.
In that you are hardcoding the fontsizes in XAML, what's so bad about hardcoding margins to create the effect you are looking for?
This will also mean that you only need to do the calcuation once, rather than forcing the app to do it every time the page is laid out.

Resources