Skip to content

Commit 244f1b1

Browse files
committed
make into a more typical control interface, expose content template, selector, orientation etc
1 parent 5f44794 commit 244f1b1

File tree

9 files changed

+241
-230
lines changed

9 files changed

+241
-230
lines changed

MainDemo.Wpf/Buttons.xaml

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
<RowDefinition Height="Auto" />
2626
<RowDefinition Height="Auto" />
2727
<RowDefinition Height="Auto" />
28-
<RowDefinition />
29-
<RowDefinition />
30-
<RowDefinition />
31-
<RowDefinition />
32-
<RowDefinition />
33-
<RowDefinition />
34-
<RowDefinition />
35-
<RowDefinition />
28+
<RowDefinition Height="Auto" />
29+
<RowDefinition Height="Auto" />
30+
<RowDefinition Height="Auto" />
31+
<RowDefinition Height="Auto" />
32+
<RowDefinition Height="Auto" />
33+
<RowDefinition Height="Auto" />
34+
<RowDefinition Height="Auto" />
35+
<RowDefinition Height="Auto" />
3636
</Grid.RowDefinitions>
3737
<TextBlock>Buttons</TextBlock>
3838
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0 24 0 0">
@@ -154,22 +154,26 @@
154154
</StackPanel>
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">
157-
<wpf:RatingBar x:Name="ratingBar" MaxRating="5" Rating="2">
158-
<wpf:RatingBar.RatingItemTemplate>
159-
<DataTemplate>
160-
<Viewbox Width="21" Height="21">
161-
<Canvas Width="24" Height="24">
162-
<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"
163-
Fill="{StaticResource PrimaryHueMidBrush}" />
164-
</Canvas>
165-
</Viewbox>
157+
<wpf:RatingBar Value="3" x:Name="BasicRatingBar" />
158+
<TextBlock Text="{Binding ElementName=BasicRatingBar, Path=Value, StringFormat=Rating: {0}}" VerticalAlignment="Top" Margin="10,2,0,0" />
159+
<wpf:RatingBar x:Name="CustomRatingBar" Max="3" Value="2" Margin="24 0 0 0" Orientation="Vertical">
160+
<wpf:RatingBar.ValueItemTemplate>
161+
<DataTemplate DataType="system:Int32">
162+
<Grid>
163+
<Viewbox Width="24" Height="24">
164+
<Canvas Width="24" Height="24">
165+
<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"
166+
Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Control}, Path=Foreground}" />
167+
</Canvas>
168+
</Viewbox>
169+
<TextBlock Text="{Binding}" HorizontalAlignment="Center" VerticalAlignment="Center"
170+
FontSize="8"
171+
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}"/>
172+
</Grid>
166173
</DataTemplate>
167-
</wpf:RatingBar.RatingItemTemplate>
174+
</wpf:RatingBar.ValueItemTemplate>
168175
</wpf:RatingBar>
169-
<TextBlock Text="Rating: " VerticalAlignment="Center" Margin="10,0,0,0" />
170-
<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-
<TextBlock Text="disabled" VerticalAlignment="Center" Margin="10,0,0,0" />
176+
<TextBlock Text="{Binding ElementName=CustomRatingBar, Path=Value, StringFormat=Rating: {0}}" VerticalAlignment="Top" Margin="10,2,0,0" />
173177
</StackPanel>
174178
</Grid>
175179
</UserControl>

MainDemo.Wpf/Buttons.xaml.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public partial class Buttons : UserControl
2222
{
2323
public Buttons()
2424
{
25-
InitializeComponent();
26-
27-
ratingTextBlock.DataContext = ratingBar;
25+
InitializeComponent();
2826
}
2927

3028
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)

MaterialDesignThemes.Wpf/Converters/RatingToBoolConverter.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@
213213
<Compile Include="Converters\NotConverter.cs" />
214214
<Compile Include="Converters\NotNullToVisibilityConverter.cs" />
215215
<Compile Include="Converters\NotZeroToVisibilityConverter.cs" />
216-
<Compile Include="Converters\RatingToBoolConverter.cs" />
217216
<Compile Include="Converters\SizeToRectConverter.cs" />
218217
<Compile Include="CustomPopupPlacementCallbackHelper.cs" />
219218
<Compile Include="DataGridAssist.cs" />
@@ -242,6 +241,7 @@
242241
<DesignTimeSharedInput>True</DesignTimeSharedInput>
243242
</Compile>
244243
<Compile Include="RatingBar.cs" />
244+
<Compile Include="RatingBarButton.cs" />
245245
<Compile Include="TextFieldAssist.cs" />
246246
<Compile Include="Converters\TextFieldHintVisibilityConverter.cs" />
247247
<Compile Include="TimePicker.cs" />

0 commit comments

Comments
 (0)