Last active
December 12, 2015 04:38
-
-
Save belsrc/4715772 to your computer and use it in GitHub Desktop.
WPF Gravatar Image Binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Cgum; // Common methods - EncryptMd5() [personal library] | |
// init: Gravatar = GetAvatar( email ) | |
public static readonly DependencyProperty GravatarProperty = | |
DependencyProperty.Register( "Gravatar", | |
typeof( BitmapImage ), | |
typeof( SingleCustomerVM ), | |
new PropertyMetadata( | |
new BitmapImage() | |
) | |
); | |
public BitmapImage Gravatar { | |
get { return ( BitmapImage )GetValue( GravatarProperty ); } | |
set { SetValue( GravatarProperty, value ); } | |
} | |
private BitmapImage GetAvatar( string email ) { | |
string hash = email.Trim().ToLower().EncryptMd5(); | |
string url = "http://www.gravatar.com/avatar/" + hash + "&size=60&d=mm"; | |
return new BitmapImage( new Uri( url.ToLower() ) ); | |
} | |
/* | |
XAML | |
<Image x:Name="imgGravatar" | |
HorizontalAlignment="Left" | |
Height="60" | |
VerticalAlignment="Top" | |
Width="60" | |
Source="{Binding Gravatar, Mode=OneWay}" /> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment