Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "half" rating selection #2764

Merged
merged 14 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions MainDemo.Wpf/RatingBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,180 @@
VerticalAlignment="Top"
Margin="10,2,0,0"/>
</StackPanel>

<TextBlock
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
Text="Rating bar with preview"/>

<StackPanel
Margin="0 16 0 0"
Orientation="Horizontal">
<smtx:XamlDisplay
UniqueKey="previewRatingBar_1"
VerticalContentAlignment="Top"
Margin="5 0 0 5">
<materialDesign:RatingBar
x:Name="BasicRatingBarWithPreview"
Value="3"
IsPreviewValueEnabled="True"/>
</smtx:XamlDisplay>

<TextBlock
Text="{Binding ElementName=BasicRatingBarWithPreview, Path=Value, StringFormat=Rating: {0}}"
VerticalAlignment="Top"
Margin="10,2,0,0"/>

<smtx:XamlDisplay
UniqueKey="previewRatingBar_2"
Margin="24 0 0 5">
<materialDesign:RatingBar
x:Name="CustomRatingBarWithPreview"
Max="3"
Value="2"
IsPreviewValueEnabled="True"
Orientation="Vertical">
<materialDesign:RatingBar.ValueItemTemplate>
<DataTemplate DataType="system:Int32">
<Grid>
<materialDesign:PackIcon
Kind="Heart"
Height="24"
Width="24"/>
<TextBlock
Text="{Binding}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="8"
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}"/>
</Grid>
</DataTemplate>
</materialDesign:RatingBar.ValueItemTemplate>
</materialDesign:RatingBar>
</smtx:XamlDisplay>
<TextBlock
Text="{Binding ElementName=CustomRatingBarWithPreview, Path=Value, StringFormat=Rating: {0}}"
VerticalAlignment="Top"
Margin="10,2,0,0"/>
</StackPanel>

<TextBlock
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
Text="Rating bar with fractional values"/>

<StackPanel
Margin="0 16 0 0"
Orientation="Horizontal">
<smtx:XamlDisplay
UniqueKey="fractionalRatingBar_1"
VerticalContentAlignment="Top"
Margin="5 0 0 5">
<materialDesign:RatingBar
x:Name="BasicRatingBarFractional"
Min="0"
Max="5"
Value="0"
ValueIncrements="0.25"
ValueChanged="BasicRatingBarFractional_ValueChanged"/>
</smtx:XamlDisplay>

<TextBlock
Text="{Binding ElementName=BasicRatingBarFractional, Path=Value, StringFormat=Rating: {0}}"
VerticalAlignment="Top"
Margin="10,2,0,0"/>

<smtx:XamlDisplay
UniqueKey="fractionalRatingBar_2"
Margin="24 0 0 5">
<materialDesign:RatingBar
x:Name="CustomRatingBarFractional"
Min="0"
Max="3"
Value="2"
ValueIncrements="0.25"
Orientation="Vertical">
<materialDesign:RatingBar.ValueItemTemplate>
<DataTemplate DataType="system:Int32">
<Grid>
<materialDesign:PackIcon
Kind="Heart"
Height="24"
Width="24"/>
<TextBlock
Text="{Binding}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="8"
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}"/>
</Grid>
</DataTemplate>
</materialDesign:RatingBar.ValueItemTemplate>
</materialDesign:RatingBar>
</smtx:XamlDisplay>
<TextBlock
Text="{Binding ElementName=CustomRatingBarFractional, Path=Value, StringFormat=Rating: {0}}"
VerticalAlignment="Top"
Margin="10,2,0,0"/>
</StackPanel>

<TextBlock
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
Text="Rating bar with preview and fractional values"/>

<StackPanel
Margin="0 16 0 0"
Orientation="Horizontal">
<smtx:XamlDisplay
UniqueKey="fractionalPreviewRatingBar_1"
VerticalContentAlignment="Top"
Margin="5 0 0 5">
<materialDesign:RatingBar
x:Name="BasicRatingBarFractionalPreview"
Min="0"
Max="5"
Value="0"
ValueIncrements="0.25"
IsPreviewValueEnabled="True"/>
</smtx:XamlDisplay>

<TextBlock
Text="{Binding ElementName=BasicRatingBarFractionalPreview, Path=Value, StringFormat=Rating: {0}}"
VerticalAlignment="Top"
Margin="10,2,0,0"/>

<smtx:XamlDisplay
UniqueKey="fractionalPreviewRatingBar_2"
Margin="24 0 0 5">
<materialDesign:RatingBar
x:Name="CustomRatingBarFractionalPreview"
Min="0"
Max="3"
Value="2"
ValueIncrements="0.25"
IsPreviewValueEnabled="True"
Orientation="Vertical">
<materialDesign:RatingBar.ValueItemTemplate>
<DataTemplate DataType="system:Int32">
<Grid>
<materialDesign:PackIcon
Kind="Heart"
Height="24"
Width="24"/>
<TextBlock
Text="{Binding}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="8"
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}"/>
</Grid>
</DataTemplate>
</materialDesign:RatingBar.ValueItemTemplate>
</materialDesign:RatingBar>
</smtx:XamlDisplay>
<TextBlock
Text="{Binding ElementName=CustomRatingBarFractionalPreview, Path=Value, StringFormat=Rating: {0}}"
VerticalAlignment="Top"
Margin="10,2,0,0"/>
</StackPanel>
</StackPanel>
</UserControl>

5 changes: 4 additions & 1 deletion MainDemo.Wpf/RatingBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ public partial class RatingBar
{
public RatingBar() => InitializeComponent();

private void BasicRatingBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<int> e)
private void BasicRatingBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
=> Debug.WriteLine($"BasicRatingBar value changed from {e.OldValue} to {e.NewValue}.");

private void BasicRatingBarFractional_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
=> Debug.WriteLine($"BasicRatingBarFractional value changed from {e.OldValue} to {e.NewValue}.");
}
}
2 changes: 1 addition & 1 deletion MaterialDesign3.Demo.Wpf/RatingBar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class RatingBar
{
public RatingBar() => InitializeComponent();

private void BasicRatingBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<int> e)
private void BasicRatingBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
=> Debug.WriteLine($"BasicRatingBar value changed from {e.OldValue} to {e.NewValue}.");
}
}
Loading