IdenticonElement Class

Element that renders and displays an identicon.
public class IdenticonElement : FrameworkElement

Examples

Place the IdenticonElement where you want an identicon to be rendered in your application. Don't forget to add the Jdenticon XML namespace.

Example usage in WPF
<Window x:Class="SampleApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:jd="clr-namespace:Jdenticon.Wpf;assembly=Jdenticon.Wpf"
        Title="MainWindow" Height="250" Width="600">
    <Window.Resources>
        <Style TargetType="{x:Type jd:IdenticonElement}">
            <Setter Property="Width" Value="100" />
            <Setter Property="Height" Value="100" />
            <Setter Property="Margin" Value="10" />
        </Style>
    </Window.Resources>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <jd:IdenticonElement Value="icon1" />
        <jd:IdenticonElement Value="icon2" />
        <jd:IdenticonElement Value="icon3" />
        <jd:IdenticonElement Value="icon4" />
    </StackPanel>
</Window>

This is the resulting application:

Sample WPF application with four identicons

Binding

To make the identicon useful you probably want to bind a value to the icon. The value decides what the icon will look like.

Example usage in WPF
<jd:IdenticonElement Value="{Binding Path=UserID}" />

Styling

The colors of the identicons can be customized using the stying properties. A suggestion is to create a style for your identicons that is used throughout the application to ensure a consistent look. You can use the icon designer to create a style.

Custom style
<Window x:Class="SampleApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:jd="clr-namespace:Jdenticon.Wpf;assembly=Jdenticon.Wpf"
        Title="MainWindow" Height="250" Width="600">
    <Window.Resources>
        <Style TargetType="{x:Type jd:IdenticonElement}">
            <Setter Property="Width" Value="100" />
            <Setter Property="Height" Value="100" />
            <Setter Property="Margin" Value="10" />

            <!-- Custom identicon style -->
            <!-- https://jdenticon.com/icon-designer.html?config=2a4766ff10cf303054545454 -->
            <Setter Property="Hues" Value="207deg"/>
            <Setter Property="Background" Value="#2a4766"/>
            <Setter Property="ColorLightness" Value="0.84, 0.84"/>
            <Setter Property="GrayscaleLightness" Value="0.84, 0.84"/>
            <Setter Property="ColorSaturation" Value="0.48"/>
            <Setter Property="GrayscaleSaturation" Value="0.48"/>
        </Style>
    </Window.Resources>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <jd:IdenticonElement Value="icon1" />
        <jd:IdenticonElement Value="icon2" />
        <jd:IdenticonElement Value="icon3" />
        <jd:IdenticonElement Value="icon4" />
    </StackPanel>
</Window>

Here is what the icons above look like:

Identicons with custom style

Constructors

Public methodIdenticonElement
Initializes a new instance of the IdenticonElement class

Properties

Public propertyBackground
Gets or sets the background of the identicon.
Public propertyColorLightness
The lightness range of the colored shapes in the icon. Default value is 0.4f - 0.8f.
Public propertyColorSaturation
The saturation of the colored shapes in the icon. Valid values are [0.0f, 1.0f]. Default value is 0.05f.
Public propertyGrayscaleLightness
The lightness range of the grayscale shapes in the icon. Default value is 0.3f - 0.9f.
Public propertyGrayscaleSaturation
The saturation of the by default grayscale shapes in the icon. The same hue is used for colored and grayscale shapes. Valid values are [0.0f, 1.0f]. Default value is 0f.
Public propertyHues
Gets or sets a string containing one or multiple hues, that the identicon will be limited to use.
Public propertyIconGenerator
Gets or sets the IconGenerator that is responsible for generating the icon patterns. This property is null when the default generator is used.
Public propertyIdenticonStyle
Gets or sets an IdenticonStyle that will affect the appearance of the generated icon.
Public propertyPadding
Gets or sets the padding between the edge of the image and the bounds of the rendered icon. The value is specified in percent in the range [0.0, 0.4]. Default value is 0.08f.
Public propertyCode exampleValue
Gets or sets a value that the generated identicon will be based upon. A string representation of the value will be hashed using SHA1.

Fields

Public fieldStatic memberBackgroundProperty
Identifies the Background dependency property.
Public fieldStatic memberColorLightnessProperty
Identifies the ColorLightness dependency property.
Public fieldStatic memberColorSaturationProperty
Identifies the ColorSaturation dependency property.
Public fieldStatic memberGrayscaleLightnessProperty
Identifies the GrayscaleLightness dependency property.
Public fieldStatic memberGrayscaleSaturationProperty
Identifies the GrayscaleSaturation dependency property.
Public fieldStatic memberHuesProperty
Identifies the Hues dependency property.
Public fieldStatic memberIconGeneratorProperty
Identifies the IconGenerator dependency property.
Public fieldStatic memberPaddingProperty
Identifies the Padding dependency property.
Public fieldStatic memberValueProperty
Identifies the Value dependency property.

See Also

Reference