From fd501dfe84d9f989c00b368291eca812f14002a0 Mon Sep 17 00:00:00 2001 From: BratchedDev Date: Mon, 30 Mar 2015 22:32:25 +0200 Subject: [PATCH 1/4] Create README.md --- README.md | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f7c88b --- /dev/null +++ b/README.md @@ -0,0 +1,183 @@ +# Bratched.Tools.RatingControl + +![](http://dev.bratched.com/fr/wp-content/uploads/sites/2/2015/03/RateControlIcon_100x100.png) + +a complete xaml rating control + +## Introduction ## + +The Bratched Rating Control is used to show or Edit rate information. + +This solution include : + + * common RatingControl source code + * Project to build Rating control in Universal App, WP8.1, WP8.0, WP7.0 + * Demo source in Universal App, WP8.1, WP8.0, WP7.0 + +Compatible with: + + * Windows Phone 7.1 + * Windows Phone 8 + * Windows Phone 8.1 + * Windows 8.1 (WINRT App) + + +## How to use it ? ## + +###Nuget +There is a [nuget package](https://www.nuget.org/packages/BratchedTools.RatingControl/) to easily add RatingControl in your project. + +![](http://dev.bratched.com/fr/wp-content/uploads/sites/2/2015/03/NugetRatingControl.png) + +In your solution, choose manage nuget package and install Bratched Rating Control. + +###Into the XAML Header Page of your project +Into the Page header add : + +####Windows Phone 7 + xmlns:rating="clr-namespace:Bratched.Tools.RatingControl.Controls;assembly=Bratched.Tools.RatingControl_wp71" + +####Windows Phone 8.0 + + xmlns:rating="clr-namespace:Bratched.Tools.RatingControl.Controls;assembly=Bratched.Tools.RatingControl_wp80" + +####Windows Phone 8.1 + + xmlns:rating="clr-namespace:Bratched.Tools.RatingControl.Controls;assembly=Bratched.Tools.RatingControl_wp81" + +####Universal Apps, Windows 8 and Windows Phone 8.1 XAML app + + xmlns:rating="clr-namespace:Bratched.Tools.RatingControl" + +###Into the XAML Page + +Add the rate control with this code + + + +![](http://dev.bratched.com/fr/wp-content/uploads/sites/2/2015/03/VisualStudioRatingControl.png) + +##Main Properties of the RatingControl + +###ItemsCount +To change the number of rate items + +###Value +The value of the rate + +###IsEditable +* False : Not Editable +* True : User can change the value with click or tap + +###ItemsSpacing +Space between each items in percent. +Each items has a theoretical width of 100 units. To have the same space that an item you need to have 100 in this value. + +###ItemTemplate +Choose predefined forms to change star rate to other pattern like : + +* Heart +* Like +* Smiley +* Trophy +* Star + +note: You can also define your own pattern +*(see in advanced properties)* + +###RoundValueSlice + +Round the Editing value. + +**example 1 : RoundValueSlice = 0.5** +will accept only values like 0.5, 1, 1.5, 2, 2.5, ... + +**example 2 : RoundValueSlice = 0.25** +will accept only values like 0.25, 0.5, 0.75, 1, 1.25, 1.5, ... + +if RoundValueSlice == 0,all the values are accepted. + +## Advanced Properties of the RatingControl +### Principe +You can personalize aspect of ratingcontrols with 2 lists of properties : + +* EmptyItemsDefinition +* FullItemsDefinition + +To change background color of the empty rate items you can use this syntax (Change the background color of the default yellow star in Red): + + + + + + + +To Change the background color of the full rate items you can use this syntax. + + + + + + + +Of course you can combine empty and full items but you can also define cyclic schemes like this. + +*(first empty items are in green, last are in yellow and all the selected items are red)* + + + + + + + + + + + +### RateItemsDefinition properties + +#### BackgroundColor +The color of the item + +#### OutlineColor +The color of the outline of the figure + +#### OutlineThikness +The depth of the outline of the figure + +#### PathData +The geometry Path Data of the figure in a string. +See [https://msdn.microsoft.com/fr-fr/library/ms752293(v=vs.110).aspx](https://msdn.microsoft.com/fr-fr/library/ms752293(v=vs.110).aspx) + +Example with all the properties + + + + + + + + + + + ![](http://dev.bratched.com/fr/wp-content/uploads/sites/2/2015/03/VisualStudioRatingControl2.png) + +##Version history + + * v1.0 + + * First public release of the current implementation. + + + + From 26b3313aacbdf84050cdb9856bcd08bb2b22d01c Mon Sep 17 00:00:00 2001 From: BratchedDev Date: Mon, 30 Mar 2015 22:44:38 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f7c88b..c3d1130 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ a complete xaml rating control +More informations in +* [http://dev.bratched.com/fr](http://dev.bratched.com/fr) +* [http://www.bratched.com](http://www.bratched.com) + + ## Introduction ## The Bratched Rating Control is used to show or Edit rate information. @@ -171,7 +176,7 @@ Example with all the properties ![](http://dev.bratched.com/fr/wp-content/uploads/sites/2/2015/03/VisualStudioRatingControl2.png) - + ##Version history * v1.0 From a884443cfea050a3020df6cc62144f53965d0c44 Mon Sep 17 00:00:00 2001 From: Mitch Capper Date: Wed, 14 Oct 2015 22:10:49 -0700 Subject: [PATCH 3/4] Added AllowHover option to prevent hover controls from changing the rating by setting to false --- .../RatingControl/RatingControl.xaml.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs b/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs index aa1f531..fafb0bb 100644 --- a/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs +++ b/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs @@ -104,6 +104,7 @@ private void InitDefaultValues() Margin = new Thickness(0); Background = new SolidColorBrush(Colors.Transparent); IsEditable = false; + AllowHover = true; Value = 0; } @@ -445,8 +446,12 @@ public bool IsEditable get { return (bool)GetValue(IsEditableProperty); } set { SetValue(IsEditableProperty, value); } } + public bool AllowHover { + get { return (bool)GetValue(AllowHoverProperty); } + set { SetValue(AllowHoverProperty, value); } + } + - public static readonly DependencyProperty ItemsCountProperty = DependencyProperty.Register("ItemsCount", typeof(Int32), typeof(RatingControl), new PropertyMetadata(Int32.MinValue, ItemsCountChanged)); @@ -461,6 +466,8 @@ public bool IsEditable public static readonly DependencyProperty IsEditableProperty = DependencyProperty.Register("IsEditable", typeof(bool), typeof(RatingControl), null); + public static readonly DependencyProperty AllowHoverProperty = + DependencyProperty.Register("AllowHover", typeof(bool), typeof(RatingControl), null); public static readonly DependencyProperty ItemTemplateProperty = DependencyProperty.Register("ItemTemplate", typeof(Templates), typeof(RatingControl), @@ -551,7 +558,7 @@ private static void DefinitionCyclesChanged(DependencyObject d, DependencyProper #if NETFX_CORE private void gridRating_PointerMoved(object sender, PointerRoutedEventArgs e) { - if (IsEditable && IsEnabled && Visibility==Visibility.Visible && rateItems != null && rateItems.Children.Any()) + if (IsEditable && (AllowHover || e.Pointer.IsInContact) && IsEnabled && Visibility==Visibility.Visible && rateItems != null && rateItems.Children.Any()) { e.Handled = true; System.Diagnostics.Debug.WriteLine("PointerMoved {0}", DateTime.Now); @@ -566,7 +573,7 @@ private void gridRating_PointerMoved(object sender, PointerRoutedEventArgs e) #if WINDOWS_PHONE void RatingControl_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e) { - if (IsEditable && IsEnabled && Visibility == Visibility.Visible && e != null && e.ManipulationOrigin != null) + if (IsEditable && AllowHover && IsEnabled && Visibility == Visibility.Visible && e != null && e.ManipulationOrigin != null) { e.Handled = true; System.Diagnostics.Debug.WriteLine("ManipulationDelta {0} - {1}", DateTime.Now, e.ManipulationOrigin.X); From 0ceb129f6f9103c47e2f4772616ab7e04e2e4443 Mon Sep 17 00:00:00 2001 From: Mitch Capper Date: Wed, 14 Oct 2015 22:18:41 -0700 Subject: [PATCH 4/4] Move debug lines under a const value to prevent spamming other applications --- .../RatingControl/RatingControl.xaml.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs b/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs index aa1f531..40fd60d 100644 --- a/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs +++ b/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs @@ -26,6 +26,7 @@ public enum DefinitionCycles { Repeat, Linear } public partial class RatingControl : UserControl { + private const bool DEBUG_MODE = false; public RatingControl() { EmptyItemsDefinition = new List(); @@ -53,7 +54,7 @@ private void ChangeItemsValue(double x) { #if NETFX_CORE Value = x / 100; -#endif +#endif #if WINDOWS_PHONE // Value = x / 100; return; @@ -62,9 +63,10 @@ private void ChangeItemsValue(double x) double marginX = (ActualWidth - realWidth) / 2; if (rateItems.Children.Any() && realWidth > 0) Value = (x - marginX) / (realWidth) * ItemsCount; - System.Diagnostics.Debug.WriteLine(String.Format("New Value {0}, ActualWidth {1}, realWidth {2}, margin {3}, X={4} ", Value, ActualWidth, realWidth, marginX, x)); + if (DEBUG_MODE) + System.Diagnostics.Debug.WriteLine(String.Format("New Value {0}, ActualWidth {1}, realWidth {2}, margin {3}, X={4} ", Value, ActualWidth, realWidth, marginX, x)); #endif - } + } #if NETFX_CORE void RatingControl_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args) @@ -553,8 +555,9 @@ private void gridRating_PointerMoved(object sender, PointerRoutedEventArgs e) { if (IsEditable && IsEnabled && Visibility==Visibility.Visible && rateItems != null && rateItems.Children.Any()) { - e.Handled = true; - System.Diagnostics.Debug.WriteLine("PointerMoved {0}", DateTime.Now); + e.Handled = true; + if (DEBUG_MODE) + System.Diagnostics.Debug.WriteLine("PointerMoved {0}", DateTime.Now); PointerPoint p = e.GetCurrentPoint(rateItems.Children.First()); if (p != null && p.Position != null) ChangeItemsValue(p.Position.X); @@ -569,7 +572,8 @@ void RatingControl_ManipulationDelta(object sender, System.Windows.Input.Manipul if (IsEditable && IsEnabled && Visibility == Visibility.Visible && e != null && e.ManipulationOrigin != null) { e.Handled = true; - System.Diagnostics.Debug.WriteLine("ManipulationDelta {0} - {1}", DateTime.Now, e.ManipulationOrigin.X); + if (DEBUG_MODE) + System.Diagnostics.Debug.WriteLine("ManipulationDelta {0} - {1}", DateTime.Now, e.ManipulationOrigin.X); double x = e.ManipulationOrigin.X; ChangeItemsValue(x); } @@ -584,7 +588,8 @@ void RatingControl_MouseLeftButtonDown(object sender, System.Windows.Input.Mouse if (p != null) { ChangeItemsValue(p.X); - System.Diagnostics.Debug.WriteLine("PointerMoved {0} - {1}", DateTime.Now, p.X); + if (DEBUG_MODE) + System.Diagnostics.Debug.WriteLine("PointerMoved {0} - {1}", DateTime.Now, p.X); } } }