Skip to content

Instantly share code, notes, and snippets.

View felipebaltazar's full-sized avatar
👋

Felipe Baltazar felipebaltazar

👋
View GitHub Profile
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TeuNamespace.ateapastadosconverters"
x:Class="TeuNamespace.TuaPage">
<!---Aqui vc registra um singleton do conversor e da uma chave pra usar ele no xaml--->
<ContentPage.Resources>
<ResourceDictionary>
<local:ByteToImageSource x:Key="byteToImgSource" />
</ResourceDictionary>
</ContentPage.Resources>
public class ByteToImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ImageSource.FromStream(() => new MemoryStream((byte[])value));;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
public class MovieViewModel : BaseViewModel
{
private string name = string.Empty;
private string image = string.Empty;
public string Name
{
get => name;
set => SetProperty(ref name, value);
<Label Text="{Binding Name}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
TextColor="White"/>
<Image HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Aspect="AspectFill"
Source="{Binding Path=Image}" />
namespace Xamarin.Theming.Droid
{
[Activity(Label = "Xamarin.Theming", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
private const float DEFAULT_SIGMA = -6f;
internal static SKImageFilter ToSKDropShadow(this Color shadowColor, float distance)
{
return SKImageFilter.CreateDropShadow(
distance,
distance,
DEFAULT_SIGMA,
DEFAULT_SIGMA,
shadowColor.ToSKColor(),
SKDropShadowImageFilterShadowMode.DrawShadowOnly);
protected override void DrawControl(SKPaint paint, SKPaintSurfaceEventArgs args)
{
var info = args.Info;
var surface = args.Surface;
var canvas = surface.Canvas;
var fShadowBlur = Convert.ToSingle(ShadowBlur);
var padding = fShadowBlur * 3f;
var diameter = padding * 2;
var retangleWidth = info.Width - diameter;
<ListView ItemsSource="{Binding ListaDeOpcoes}" local:ItemTappedAttached.Command="{Binding OpcaoSelecionadaCommand}>
public class ItemTappedAttached
{
public static readonly BindableProperty CommandProperty =
BindableProperty.CreateAttached (
propertyName: "Command",
returnType: typeof(ICommand),
declaringType: typeof(ListView),
defaultValue: null,
defaultBindingMode: BindingMode.OneWay,
validateValue: null,
public sealed class MyViewModel : BaseViewModel
{
...
public MyViewModel()
{
MessagingCenter.Subscribe<NavigationEventArgs>(this, nameof(Page.OnAppearing), OnAppearing);
MessagingCenter.Subscribe<NavigationEventArgs>(this, nameof(Page.OnDisappearing), OnDisappearing);
}