xaml
<UserControl x:Class="System.Windows.Controls.Samples.RatingSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="600">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="12" />
<!-- Spacing -->
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<!-- Default Style -->
<ContentControl Content="Default Style" />
<inputToolkit:Rating x:Name="rating" Value="0.45" ItemCount="10" HorizontalAlignment="Left">
<inputToolkit:Rating.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</inputToolkit:Rating.ItemsPanel>
</inputToolkit:Rating>
<Slider Minimum="0" Maximum="1" SmallChange="0.01" Margin="0,2,0,0" Value="{Binding Path=Value, ElementName=rating, Mode=TwoWay}" HorizontalAlignment="Left" Width="200"/>
<!-- Custom Style -->
<ContentControl Content="Custom Style" />
<inputToolkit:Rating Value="0.65" Foreground="{x:Null}" Margin="0,4,0,0" ItemCount="5"/>
<ContentControl Content="Customized RatingItem Style" />
<inputToolkit:Rating Value="0.65" ItemCount="0" Margin="0,1,0,0" SelectionMode="Individual" Height="64" x:Name="rating1">
<inputToolkit:RatingItem ToolTipService.ToolTip="Hate" Content="Hate" Foreground="Black"/>
<inputToolkit:RatingItem ToolTipService.ToolTip="Bored" Content="Bored" Foreground="Black" />
<inputToolkit:RatingItem ToolTipService.ToolTip="Ease" Content="Ease" Foreground="Black" />
<inputToolkit:RatingItem ToolTipService.ToolTip="Amused" Content="Amused" Foreground="Black"/>
<inputToolkit:RatingItem ToolTipService.ToolTip="Laughter" Content="Laughter" Margin="4,0,0,0" Foreground="Black"/>
</inputToolkit:Rating>
<Button Content="Button" Height="23" Name="button1" Width="75" Click="button1_Click" />
</StackPanel>
</Grid>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="600">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="12" />
<!-- Spacing -->
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<!-- Default Style -->
<ContentControl Content="Default Style" />
<inputToolkit:Rating x:Name="rating" Value="0.45" ItemCount="10" HorizontalAlignment="Left">
<inputToolkit:Rating.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</inputToolkit:Rating.ItemsPanel>
</inputToolkit:Rating>
<Slider Minimum="0" Maximum="1" SmallChange="0.01" Margin="0,2,0,0" Value="{Binding Path=Value, ElementName=rating, Mode=TwoWay}" HorizontalAlignment="Left" Width="200"/>
<!-- Custom Style -->
<ContentControl Content="Custom Style" />
<inputToolkit:Rating Value="0.65" Foreground="{x:Null}" Margin="0,4,0,0" ItemCount="5"/>
<ContentControl Content="Customized RatingItem Style" />
<inputToolkit:Rating Value="0.65" ItemCount="0" Margin="0,1,0,0" SelectionMode="Individual" Height="64" x:Name="rating1">
<inputToolkit:RatingItem ToolTipService.ToolTip="Hate" Content="Hate" Foreground="Black"/>
<inputToolkit:RatingItem ToolTipService.ToolTip="Bored" Content="Bored" Foreground="Black" />
<inputToolkit:RatingItem ToolTipService.ToolTip="Ease" Content="Ease" Foreground="Black" />
<inputToolkit:RatingItem ToolTipService.ToolTip="Amused" Content="Amused" Foreground="Black"/>
<inputToolkit:RatingItem ToolTipService.ToolTip="Laughter" Content="Laughter" Margin="4,0,0,0" Foreground="Black"/>
</inputToolkit:Rating>
<Button Content="Button" Height="23" Name="button1" Width="75" Click="button1_Click" />
</StackPanel>
</Grid>
</UserControl>
c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace System.Windows.Controls.Samples
{
public partial class RatingSample : UserControl
{
public RatingSample()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(rating.Value.ToString());
MessageBox.Show(rating1.Value.ToString());
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace System.Windows.Controls.Samples
{
public partial class RatingSample : UserControl
{
public RatingSample()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(rating.Value.ToString());
MessageBox.Show(rating1.Value.ToString());
}
}
}