Skip to content

Instantly share code, notes, and snippets.

@belsrc
Last active December 12, 2015 04:38
Show Gist options
  • Save belsrc/4715772 to your computer and use it in GitHub Desktop.
Save belsrc/4715772 to your computer and use it in GitHub Desktop.
WPF Gravatar Image Binding
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