Skip to content

Instantly share code, notes, and snippets.

View ravero's full-sized avatar

Rafael Veronezi ravero

View GitHub Profile
OnPlatform(
(Device.iOS, () => CustomiOSAction()),
(Device.Android, () => CustomAndroidAction())
);
static void OnPlatform(params (string, Action)[] platformActions) =>
platformActions.ToList().ForEach(pa => {
if (pa.Item1 == Device.RuntimePlatform)
pa.Item2();
});
double width2 = OnPlatform(200.0, (Device.iOS, 200), (Device.Android, 150), (Device.UWP, 120));
static T OnPlatform<T>(T defValue, params (string, T)[] platformValues) {
foreach (var pv in platformValues) {
if (pv.Item1 == Device.RuntimePlatform)
return pv.Item2;
}
return defValue;
}
double width;
switch (Device.RuntimePlatform) {
case Device.iOS:
case Device.Android:
width = 200;
break;
case Device.UWP:
width = 120;
break;
}
<Button Text="Ok">
<Button.WidthRequest>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="iOS,Android">200</On>
<On Platform="UWP">120</On>
</OnPlatform>
</Button.WidthRequest>
</Button>
<Button Text="OK">
<Button.WidthRequest>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="iOS">200</On>
<On Platform="Android">150</On>
</OnPlatform>
</Button.WidthRequest>
</Button>
<ListView.HeaderTemplate>
<DataTemplate>
<ContentView>
<Label
Margin="16"
HorizontalOptions="CenterAndExpand"
Text="{Binding PhoneNumber, StringFormat='Meu número: {0}'}" />
</ContentView>
</DataTemplate>
</ListView.HeaderTemplate>
<ListView
ItemsSource="{Binding Items}"
Header="{Binding}"
Footer="{Binding}">
...
/// <summary>
/// Obtém os itens da lista.
/// </summary>
public IList<Contact> Items { get; private set; }
/// <summary>
/// Obtém o número de telefone atual.
/// </summary>
public string PhoneNumber { get; private set; } = "+55 (11) 1111-1111";