24h Format in Timepicker - xaml

I have a TimePicker and changed the Format to "HH:mm" to disable the AM-PM system. However, the picker still shows AM and PM instead of numbers from 00:00 to 23:59.
<TimePicker Time="13:00" Format="HH:mm"/>
Foto of iOS simulator

you could use custom renderer to achieve this effect :
[assembly: ExportRenderer(typeof(TimePicker), typeof(MyTimePickerRenderer))]
namespace App18.iOS
{
class MyTimePickerRenderer:TimePickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
{
base.OnElementChanged(e);
if (Control != null)
{
UIDatePicker picker = Control.InputView as UIDatePicker;
picker.Mode = UIDatePickerMode.Time;
NSLocale locale = new NSLocale("en_GB");
picker.Locale = locale;
}
}
}
}

format that you are specifying only means how user will see the value he has selected.
if you want to change the way it looks in the control itself you will have to implement custom renderer for the TimePicker. I believe this link can help you in creating the custom renderer.

Related

Xamarin.iOS does not paint secondary toolbar in the requested color

In my Xamarin project, in the header of the XAML file, I have set:
Shell.BackgroundColor="DarkGreen"
Part of xaml header declaration looks like that:
On Android all things are ok (check the picture below), but on iOS the secondary toolbar (shown in red square) is white, and I can't understand why does it happen and how can I fix this issue?
You can add on itemsApp->AppDelegate.cs->FinishedLaunching method:
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
UITabBar.Appearance.TintColor = UIColor.Blue;
UINavigationBar.Appearance.BackgroundColor = UIColor.Blue;
}
The complete method for FinishedLaunching is:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental");
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
UITabBar.Appearance.TintColor = UIColor.Blue;
UINavigationBar.Appearance.BackgroundColor = UIColor.Blue;
}
return base.FinishedLaunching(app, options);
}

How do I get notified when the user changes the dynamic text size in a Xamarin.Forms app?

I already use the named font sizes in elements that support them like labels, but I have other views where I calculate the height based on Device.GetNamedSize(). I bind the view height to a property so in principle everything should layout when the computed size changes, but how do I get notified of the event that the user has changed the accessibility text size? I need to support both Android and iOS.
You could create a custom Label
public class MyLabel :Label
{
public MyLabel()
{
PropertyChanged += MyLabel_PropertyChanged;
}
private void MyLabel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if(e.PropertyName== "FontSize")
{
// do some thing you want
}
}
}

Multiline button in Xamarin? is not working

Using
is not working. Instead my button only appears to say "First Line."
<Button Text="First Line
Second Line"/>
Am I doing this incorrectly? Is there another simple way to make the text go onto the second line?
I test it on Android,it works well,Did you run on ios ? I think this is mainly a problem with iOS because Android will wrap the text by default.
If you want run on ios,you could use customrenderer to achieve this.
[assembly: ExportRenderer(typeof(Button), typeof(iosbutton))]
namespace EntryCa.iOS
{
class iosbutton :ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.TitleLabel.LineBreakMode = UILineBreakMode.WordWrap;
Control.TitleLabel.Lines = 0;
Control.TitleLabel.TextAlignment = UITextAlignment.Center;
}
}
}
}

Xamarin.Forms fontawesome works on UWP but shows square on Android

I have added fontawesome in my projects of Xamarin.Forms, on UWP font looks as expected but on android it is square. I have set build-action to AndroidAsset but it does not work.
On Android, it's a bit of a hassle use FontAwesome. This code behind post is about how to use Font Awesome in the simplest way possible. It's as easy as using a Label once set up.
We use a custom renderer that looks at the Label in question, determines if there is one character in the text field and if that character has the value of 0xf000 or higher. If so, we replace the font with FontAwesome.
Since the icons all begin at 0xf000 or higher, the custom renderer will make sure that the correct font is used
Reference article
[assembly: ExportRenderer(typeof(Label), typeof(AwesomeRenderer))]
namespace Awesome.Droid
{
public class AwesomeRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
var label = (TextView)Control;
var text = label.Text;
if(text.Length > 1 || text[0] < 0xf000)
{
return;
}
var font = Typeface.CreateFromAsset(Xamarin.Forms.Forms.Context.ApplicationContext.Assets, "fontawesome.ttf");
label.Typeface = font;
}
}
}

How to animate SettingsFlyout on dismiss

In Windows 8.1, I'm using the new SettingsFlyout control. The flyout animates in correctly and will animate out if you use the control's built-in back button to return to the Settings Charm flyout. But if you light dismiss by clicking outside the flyout, it disappears without a transition animation.
How do you animate a transition out when you light dismiss the SettingsFlyout? (I don't want to return to the Settings Charm flyout, I just want it to slide out on a light dismiss.)
Matt, what you want to do should be easily achievable but is currently not supported by the XAML SettingsFlyout API out of the box. As Jerry points out, there are transitions that allow an animate out effect (in XAML you want EdgeUIThemeTransition). Unfortunately, there is no API support on SettingsFlyout to add this transition, but you can get it to work using your own private popup to host the SettingsFlyout (more on this below):
public sealed partial class SettingsFlyout1 : SettingsFlyout
{
Popup _p;
Border _b;
public SettingsFlyout1()
{
this.InitializeComponent();
BackClick += SettingsFlyout1_BackClick;
Unloaded += SettingsFlyout1_Unloaded;
Tapped += SettingsFlyout1_Tapped;
}
void SettingsFlyout1_BackClick(object sender, BackClickEventArgs e)
{
_b.Child = null;
SettingsPane.Show();
}
void SettingsFlyout1_Unloaded(object sender, RoutedEventArgs e)
{
if (_p != null)
{
_p.IsOpen = false;
}
}
void SettingsFlyout1_Tapped(object sender, TappedRoutedEventArgs e)
{
e.Handled = true;
}
public void ShowCustom()
{
_p = new Popup();
_b = new Border();
_b.ChildTransitions = new TransitionCollection();
// TODO: if you support right-to-left builds, make sure to test all combinations of RTL operating
// system build (charms on left) and RTL flow direction for XAML app. EdgeTransitionLocation.Left
// may need to be used for RTL (and HorizontalAlignment.Left on the SettingsFlyout below).
_b.ChildTransitions.Add(new EdgeUIThemeTransition() { Edge = EdgeTransitionLocation.Right });
_b.Background = new SolidColorBrush(Colors.Transparent);
_b.Width = Window.Current.Bounds.Width;
_b.Height = Window.Current.Bounds.Height;
_b.Tapped += b_Tapped;
this.HorizontalAlignment = HorizontalAlignment.Right;
_b.Child = this;
_p.Child = _b;
_p.IsOpen = true;
}
void b_Tapped(object sender, TappedRoutedEventArgs e)
{
Border b = (Border)sender;
b.Child = null;
}
}
Full solution for this sample: https://github.com/finnigantime/Samples/tree/master/examples/Win8Xaml/SettingsFlyout_AnimateOut
I think SettingsFlyout should have API support for your scenario, so I filed a work item on the XAML team. In the future, such requests/issues can be raised on the MSDN forum as well (moderated by MSFT folks). The limitation here is that SettingsFlyout is implemented on top of Popup with IsLightDismissEnabled="True", and the light-dismiss event currently closes the Popup immediately without allowing unloading child transitions to run. I think this can be overcome and transitions can be supported at the SettingsFlyout API level to enable your scenario.
You need to use the HideEdgeUI animation
Read this: http://msdn.microsoft.com/en-us/library/windows/apps/jj655412.aspx