This question is locked. New answers and comments are not allowed.
Hello,
I'm using RadRating Control for silverlight (2014.1.421.1050). The control is part of my user control and I would like to set number of stars dynamically using binding to dependency property. This however seems not to work - each time the number of stars equals five.
Here are some code snippets:
This is dependency property for my user control, put in code behind:
public partial class my_rating_control : UserControl
{
public my_rating_control()
{
InitializeComponent();
}
public int MaxRating
{
get { return (int)GetValue(MaxRatingProperty); }
set { SetValue(MaxRatingProperty, value); }
}
// Using a DependencyProperty as the backing store for MaxRating. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MaxRatingProperty =
DependencyProperty.Register("MaxRating", typeof(int), typeof(my_rating_control), new PropertyMetadata(5));
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Rating3.NumberOfItemsToGenerate = 7;
}
}
this is xaml for my user control:
<UserControl x:Class="rad_rating_test.my_rating_control"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
x:Name="UserControl" Loaded="UserControl_Loaded">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Rating set to 7 from xaml" Grid.Row="0" Grid.Column="0" />
<telerik:RadRating x:Name="Rating1" Grid.Row="0" HorizontalAlignment="Left" Height="23" Grid.Column="1" VerticalAlignment="Top"
NumberOfItemsToGenerate="7" />
<TextBlock Text="Rating set to 7 via binding" Grid.Row="1" Grid.Column="0" />
<telerik:RadRating x:Name="Rating2" Grid.Row="1" HorizontalAlignment="Left" Height="23" Grid.Column="1" VerticalAlignment="Top"
NumberOfItemsToGenerate="{Binding MaxRating, ElementName=UserControl}" />
<TextBlock Text="Rating set to 7 after loaded event" Grid.Row="2" Grid.Column="0" />
<telerik:RadRating x:Name="Rating3" Grid.Row="2" HorizontalAlignment="Left" Height="23" Grid.Column="1" VerticalAlignment="Top"
/>
</Grid>
</UserControl>
this is how I use this control in my main page:
<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:local="clr-namespace:rad_rating_test" x:Class="rad_rating_test.MainPage"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<local:my_rating_control Margin="0" MaxRating="7"/>
</Grid>
</UserControl>
If you run the application, only the first rating has seven stars: the one which is explicitly set to 7 in xaml: NumberOfItemsToGenerate="7". The rest have 5 stars.
Could you please tell me how to achieve the desired effect?
I'm using RadRating Control for silverlight (2014.1.421.1050). The control is part of my user control and I would like to set number of stars dynamically using binding to dependency property. This however seems not to work - each time the number of stars equals five.
Here are some code snippets:
This is dependency property for my user control, put in code behind:
public partial class my_rating_control : UserControl
{
public my_rating_control()
{
InitializeComponent();
}
public int MaxRating
{
get { return (int)GetValue(MaxRatingProperty); }
set { SetValue(MaxRatingProperty, value); }
}
// Using a DependencyProperty as the backing store for MaxRating. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MaxRatingProperty =
DependencyProperty.Register("MaxRating", typeof(int), typeof(my_rating_control), new PropertyMetadata(5));
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Rating3.NumberOfItemsToGenerate = 7;
}
}
this is xaml for my user control:
<UserControl x:Class="rad_rating_test.my_rating_control"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
x:Name="UserControl" Loaded="UserControl_Loaded">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Rating set to 7 from xaml" Grid.Row="0" Grid.Column="0" />
<telerik:RadRating x:Name="Rating1" Grid.Row="0" HorizontalAlignment="Left" Height="23" Grid.Column="1" VerticalAlignment="Top"
NumberOfItemsToGenerate="7" />
<TextBlock Text="Rating set to 7 via binding" Grid.Row="1" Grid.Column="0" />
<telerik:RadRating x:Name="Rating2" Grid.Row="1" HorizontalAlignment="Left" Height="23" Grid.Column="1" VerticalAlignment="Top"
NumberOfItemsToGenerate="{Binding MaxRating, ElementName=UserControl}" />
<TextBlock Text="Rating set to 7 after loaded event" Grid.Row="2" Grid.Column="0" />
<telerik:RadRating x:Name="Rating3" Grid.Row="2" HorizontalAlignment="Left" Height="23" Grid.Column="1" VerticalAlignment="Top"
/>
</Grid>
</UserControl>
this is how I use this control in my main page:
<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:local="clr-namespace:rad_rating_test" x:Class="rad_rating_test.MainPage"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<local:my_rating_control Margin="0" MaxRating="7"/>
</Grid>
</UserControl>
If you run the application, only the first rating has seven stars: the one which is explicitly set to 7 in xaml: NumberOfItemsToGenerate="7". The rest have 5 stars.
Could you please tell me how to achieve the desired effect?