Xamarin.Forms Android 7.0 searchbar - c#

The searchbar in forms doesn't appear on Android 7.0 devices, I am compiling with Android 6.0 not the latest version. The issue is apparently a google problem with calculating a height of the searchbar that results in a height of zero, thus no searchbar. I want to implement a searchbar size in XAML and only affect Android. Apparently, if I don't set the HeightRequest, Forms will use a default value or zero, so now the problem propagates to the other platforms. I read somewhere that if I set the HeightRequest to -1, it is invalid and Xamarin will calculate/default a height that makes sense and I can simply override the height for Android. I currently have this code in my XAML and it appears to work. I don't want to make a custom renderer, especially since the problem is apparently fixed in Android 7.1.
Anyone have a better solution?
Thanks
Alan
<SearchBar Text="{Binding Search}" Placeholder="Search order list" SearchCommand="{Binding SearchCommand}" >
<SearchBar.HeightRequest>
<OnPlatform x:TypeArguments="x:Double"
iOS="-1.0"
Android="40.0"
WinPhone="-1">
</OnPlatform>
</SearchBar.HeightRequest>
</SearchBar>

Related

Proportional fontsize on different screen resolutions - Xamarin Forms

In my Xamarin Forms project, im using named size for my labels like this :
new Setter { Property = Label.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Medium, typeof(Label)) },
My problem is depending on which resolution the device is, the fontsize is not rendered proportionnaly.
Here is what is rendered on my emulator :
And this on my device :
If the size of the text on my emulator is good, it is way too small on my device and this is what i try to avoid.
I know there is lot of question about fontsize, but never found an answer about this... Did i missed something ?
I finnaly got the problem.
In the settings, fontsizes were different between my device and the emulator.
My device was setted up on tiny fontsize while my emulator wad setted up on normal fontsize.
That explain the huge difference between them !
Why don't you use normal FontSize ? It should scale automatically depending on device size:
FontSize="20"
Your definition of medium text size may be different depending on UI NamedSize.Medium, You'll always loose control if you let the device decide what is small and what is large

SignaturePadView in Xamarin Forms different on ios and android

I have added the Nuget packages for Xamarin.Controls.SignaturePad.Forms into my xamarin forms solution. I call the GetImageStreamAsync(SignatureImageFormat.Jpg);. When I run it with White background and black stroke color it only works on ios. Android displays a black screen. THen when I try to set the background to black and White stroke color, Android displays correctly and ios displays a white block and doesn't display correctly. Does anyone have any solutions to this? Ideally it would be good to have the same background color and stroke color on either platforms. I can get around it by setting the background color and stroke color depending on OS, but that seems a bit hacky. Here's what works with the android in Xamarin Forms when I call var str = await PadView.GetImageStreamAsync(SignatureImageFormat.Jpg);. Setting a "White" Background doesn't show up in Android. It always shows a black square. Is there something I'm missing? I'm trying the source https://github.com/xamarin/SignaturePad Thanks.
<forms:SignaturePadView x:Name="PadView"
HeightRequest="100"
WidthRequest="140"
BackgroundColor="Black"
SignatureLineColor="White"
PromptText="Sign here"
PromptTextColor="Gray"
ClearText="Clear"
ClearTextColor="{StaticResource Accent}"
StrokeColor="White"
StrokeWidth="4" />
see comment - Rebuilt source and hard coded White into android background color when it creates the image of the signature. It suits what I have to do, so may not work if you want another color, or you may have to hard code your own color in the android and ios version. Didn't delve into the SignaturePad code enough to see what was going on.

Xamarin.Forms font family not working for UWP

I have been following the Xamarin guide to adding fonts to my app. I have not had any issues with iOS or Android, but my UWP app is ignoring the font and using the default font.
I added my font to my UWP project in Assets\Fonts\FiraSans-Regular.otf.
My XAML markup to apply the font is as follows:
<Label HeightRequest="50" Text="My sample text">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<OnPlatform.iOS>FiraSans-Regular</OnPlatform.iOS>
<OnPlatform.Android>FiraSans-Regular.otf#FiraSans-Regular</OnPlatform.Android>
<OnPlatform.WinPhone>Assets/Fonts/FiraSans-Regular.otf#FiraSans</OnPlatform.WinPhone>
</OnPlatform>
</Label.FontFamily>
</Label>
Does this appear to be the correct way to apply a font for my UWP app?
I've downloaded the Font and you did almost correct. Add the space in font name:
<OnPlatform.WinPhone>Assets/Fonts/FiraSans-Regular.otf#Fira Sans</OnPlatform.WinPhone>
You have to use correct font name which you can find during font installation.

Xamarin Android - Gif in WebView is displayed blank

I got an issue while trying to display a gif for my UI.
When the app is launched, the .gif file is correctly loaded (if i change the path, a loading error occure) but the webView is displayed blank.
Android version : marshmallow 6.0 API lvl 23
the "ship_sea.gif" is currently located in Assets Folder, with "Android Asset" in build action.
the axml:
<WebView
android:id="#+id/myWebGIF"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="50dp"
android:layout_marginLeft="50dp" />
the .cs :
WebView webGif = FindViewById<WebView>(Resource.Id.myWebGIF);
webGif.LoadUrl(string.Format("file:///android_asset/ship_sea.gif"));
Why is this not working? It is really simple and I can't figure out what is the problem.
Could it be the device as this post suggests (NVIDIA Shield Tablet K1)?
Ok guys, here is the answer :
Be sure that your canvas is the same size as your gif.
In my case, i had a particular large gif, and the only part rendered in my canvas was the top-left (a blank part).
The default background color for a webView is white, so it resulted in a blank view.
Problem solved : there was no error, just wrong interpretation of the problem.

Implement Flick Gesture via GestureService from Windows Phone 8

I'm working on a Windows Phone 8 app. This app will allow a user to flick a panel up. I want this to work very similarly to the way the lock screen works. When the user 'flicks' the panel up, I want it to automatically, move up accordingly. Does anyone know how to do this? Currently, I have the following:
<Grid x:Name="myGrid" Background="Peru" VerticalAlignment="Stretch">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener x:Name="myGridGestureListener" DragStarted="myGridGestureListener_DragStarted" DragDelta="myGridGestureListener_DragDelta" DragCompleted="myGridGestureListener_DragCompleted" Flick="myGridGestureListener_Flick" />
</toolkit:GestureService.GestureListener>
<Grid.RenderTransform>
<TranslateTransform x:Name="bannerGridTransform" Y="5000" />
</Grid.RenderTransform>
</Grid>
private void myGridGestureListener_Flick(object sender, FlickGestureEventArgs e)
{
if (e.Direction == System.Windows.Controls.Orientation.Vertical)
{
}
}
For the life of me, I can't figure out how to get myGrid to smoothly react to the flick gesture accordingly. I figured someone would have already implemented this, however, apparently, I'm wrong.
Thank you!
Gesture Listener is deprecated in Windows Phone 8. When you download the latest toolkit source. It contains a sample toolkit app for window phone 8. When you click the gestures, it throws a dialog which says
The GestureListener is now obsolete in windows phone 8, as the built
in manipulation and gesture events now have functional parity with it.
This sample and the sample code demonstrated how to use the
manipulation and gesture events for purposes for which one previously
would have used the GestureListener
If someone need to implement gestures in Windows Phone 8 - look at this https://github.com/PedroLamas/WPtoolkit/blob/master/PhoneToolkitSample8/Samples/GestureSample.xaml.cs
Unfortunately this isn't as trivial as a couple of lines of code on SO since you have to account for the pan while you are holding down the screen and the flick which needs to seamlessly continue on from the pan when the user lifts their finger. A great example of this is actually a darts game since you want the dart to move while you are dragging and then fly off when you release (the flick).
You can find a great example with source code at http://windowsphone7developerguide.blograby.com/darts-gesture-listener-flick-gesture/
You dont need to use toolkit gesture listener anymore. You can use in built manipulation events. Here is the sample:-
http://phone.codeplex.com/SourceControl/latest#PhoneToolkitSample8/Samples/GestureSample.xaml.cs

Categories