2016-04-14 2 views
0

Je suis en train de suivre le processus rendu personnalisé tel que défini ici:Xamaring Windows 8.1 Rendered personnalisé convertir hex à pinceau?

https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/entry/

Je suis en train de faire les fenêtres un, je suis juste courir les fenêtres, on ne le téléphone Windows. Mais je n'arrive pas à comprendre comment convertir une couleur hexadécimale dans les fenêtres requises SolidColorBrush

Comment procéder. Je deviens plutôt confus avec les différentes DLL car Color existe aussi dans la bibliothèque de classes portable, mais n'est pas compatible.

Si quelqu'un pouvait tester cela et me montrer une copie de travail qui serait vraiment appréciée. Ai-je manqué une référence?

using Windows.UI; 
using Windows.UI.Xaml.Media; 
using Hello.Renderer; 
using Hello.Windows.Renderer; 
using Xamarin.Forms; 
using Xamarin.Forms.Platform.WinRT; 

[assembly:ExportRenderer(typeof(MyEntry), typeof(MyEntryRenderer))] 
namespace Hello.Windows.Renderer 
{ 
    public class MyEntryRenderer : EntryRenderer 
    { 
     protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) 
     { 
      base.OnElementChanged(e); 

      if (Control != null) 
      { 
       Control.Background = (SolidColorBrush)new ColorConverter().Convert("#FF6A00", null, null, null); 
      } 
     } 
    } 
} 

Répondre

1

Essayez avec this converter:

public static SolidColorBrush GetColorFromHexa(string hexaColor) 
{ 
    return new SolidColorBrush(
     Color.FromArgb(
      255, 
      Convert.ToByte(hexaColor.Substring(1, 2), 16), 
      Convert.ToByte(hexaColor.Substring(3, 2), 16), 
      Convert.ToByte(hexaColor.Substring(5, 2), 16) 
     ) 
    ); 
} 
+0

Un grand merci qui fonctionne :) – Andrew