Thursday, March 11, 2010

Rating Control for WPF 4.0

image

Being recently frustrated with the absence of an acceptable rating control for WPF, I ported the rating control from the Silverlight toolkit to WPF.  A link to the full source code is provided below.  To use the code you will need Microsoft Visual Studio 2010 and .NET 4.0 (currently available as a free downloadable “release candidate”).

The follow code snippet demonstrates how to use the rating control in XAML.

<Window x:Class="ESRI.PrototypeLab.Rating.Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:rating="clr-namespace:ESRI.PrototypeLab.Rating;
assembly=ESRI.PrototypeLab.Rating"
Title="Rating control for WPF" Height="200" Width="300" > <Grid> <StackPanel Orientation="Vertical" HorizontalAlignment="Center"
VerticalAlignment="Center"> <rating:Rating x:Name="rating"
Value="{Binding ElementName=slider, Path=Value, Mode=TwoWay}"
ItemCount="5" HorizontalAlignment="Left"
Background="Transparent" Foreground="Yellow" /> <Slider x:Name="slider" Minimum="0" Maximum="1"
SmallChange="0.1" LargeChange="0.1" Value="0"/> </StackPanel> </Grid> </Window>

Click here for the source code.

1 comment:

  1. After posting this I discovered that that February 2010 release of the WPF Toolkit was published a few days ago. The latest toolkit includes a Rating component.
    http://wpf.codeplex.com/releases/view/40535

    ReplyDelete