Skip to content

Commit 9350f65

Browse files
committed
default icon for the RatingBar
1 parent 3c4ab94 commit 9350f65

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

MainDemo.Wpf/Buttons.xaml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
<TextBlock Margin="0 24 0 0" Grid.Row="9">Rating bar</TextBlock>
156156
<StackPanel Grid.Row="10" Margin="0 16 0 0" Orientation="Horizontal">
157157
<wpf:RatingBar x:Name="ratingBar" MaxRating="5" Rating="2">
158-
<wpf:RatingBar.ButtonContentTemplate>
158+
<wpf:RatingBar.RatingItemTemplate>
159159
<DataTemplate>
160160
<Viewbox Width="21" Height="21">
161161
<Canvas Width="24" Height="24">
@@ -164,23 +164,12 @@
164164
</Canvas>
165165
</Viewbox>
166166
</DataTemplate>
167-
</wpf:RatingBar.ButtonContentTemplate>
167+
</wpf:RatingBar.RatingItemTemplate>
168168
</wpf:RatingBar>
169169
<TextBlock Text="Rating: " VerticalAlignment="Center" Margin="10,0,0,0" />
170170
<TextBlock x:Name="ratingTextBlock" Text="{Binding Path=Rating, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" />
171-
<wpf:RatingBar MaxRating="7" Rating="5" IsEnabled="False" Margin="20,0,0,0" Width="224">
172-
<wpf:RatingBar.ButtonContentTemplate>
173-
<DataTemplate>
174-
<Viewbox Width="21" Height="21">
175-
<Canvas Width="24" Height="24">
176-
<Path Data="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"
177-
Fill="{StaticResource PrimaryHueMidBrush}" />
178-
</Canvas>
179-
</Viewbox>
180-
</DataTemplate>
181-
</wpf:RatingBar.ButtonContentTemplate>
182-
</wpf:RatingBar>
183-
<TextBlock Text="disabled" VerticalAlignment="Center" Margin="10,0,0,0" />
171+
<wpf:RatingBar MaxRating="7" Rating="5" IsEnabled="False" Margin="20,0,0,0" Width="224" />
172+
<TextBlock Text="disabled" VerticalAlignment="Center" Margin="10,0,0,0" />
184173
</StackPanel>
185174
</Grid>
186175
</UserControl>

MaterialDesignThemes.Wpf/RatingBar.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ public class RatingBar : Control
1717
{
1818
private const string RatingBarGridPartName = "PART_ratingBarGrid";
1919

20-
private static readonly DependencyProperty ButtonContentTemplateProperty = DependencyProperty.Register("ButtonContentTemplate", typeof(DataTemplate), typeof(RatingBar));
21-
22-
public DataTemplate ButtonContentTemplate
23-
{
24-
get { return (DataTemplate)GetValue(ButtonContentTemplateProperty); }
25-
26-
set {
27-
SetValue(ButtonContentTemplateProperty, value);
28-
29-
RebuildUi();
30-
}
31-
}
32-
3320
public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register("MaxRating", typeof(int), typeof(RatingBar));
3421

3522
public int MaxRating
@@ -75,6 +62,20 @@ public int Rating
7562
}
7663
}
7764

65+
private static readonly DependencyProperty RatingItemTemplateProperty = DependencyProperty.Register("RatingItemTemplate", typeof(DataTemplate), typeof(RatingBar));
66+
67+
public DataTemplate RatingItemTemplate
68+
{
69+
get { return (DataTemplate)GetValue(RatingItemTemplateProperty); }
70+
71+
set
72+
{
73+
SetValue(RatingItemTemplateProperty, value);
74+
75+
RebuildUi();
76+
}
77+
}
78+
7879
private Button[] _ratingButtons;
7980

8081
static RatingBar()
@@ -124,7 +125,7 @@ private void RebuildUi()
124125
for (int i = 0; i < MaxRating; i++)
125126
{
126127
Button button = new Button();
127-
button.ContentTemplate = ButtonContentTemplate;
128+
button.ContentTemplate = RatingItemTemplate;
128129

129130
button.DataContext = this;
130131
Binding enabledBinding = new Binding("IsEnabled");

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.RatingBar.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
</ControlTemplate>
1717
</Setter.Value>
1818
</Setter>
19+
<Setter Property="RatingItemTemplate">
20+
<Setter.Value>
21+
<DataTemplate>
22+
<Viewbox Width="21" Height="21">
23+
<Canvas Width="24" Height="24">
24+
<Path Data="M12,17.27L18.18,21L16.54,13.97L22,9.24L14.81,8.62L12,2L9.19,8.62L2,9.24L7.45,13.97L5.82,21L12,17.27Z"
25+
Fill="Black" />
26+
</Canvas>
27+
</Viewbox>
28+
</DataTemplate>
29+
</Setter.Value>
30+
</Setter>
1931
</Style>
2032

2133
</ResourceDictionary>

0 commit comments

Comments
 (0)