diff --git a/Demos/RatingControlDemo_ua8/RatingControlDemo_ua81/RatingControlDemo_ua81.Shared/View/MVVMPage.xaml b/Demos/RatingControlDemo_ua8/RatingControlDemo_ua81/RatingControlDemo_ua81.Shared/View/MVVMPage.xaml index f798976..3492e91 100644 --- a/Demos/RatingControlDemo_ua8/RatingControlDemo_ua81/RatingControlDemo_ua81.Shared/View/MVVMPage.xaml +++ b/Demos/RatingControlDemo_ua8/RatingControlDemo_ua81/RatingControlDemo_ua81.Shared/View/MVVMPage.xaml @@ -51,7 +51,7 @@ @@ -59,12 +59,12 @@ - + - + + Text="{Binding FullOutlineThickness, Mode=TwoWay}" /> - + + Text="{Binding EmptyOutlineThickness, Mode=TwoWay}" /> + ItemTemplate="Star" + > + +![](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 + +#### OutlineThickness +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.1 + * #Issue 4 : bad pointer moving in Windows 8.1/10 App + * AllowHover Option (thanks mitchcapper) + * debug lines in a const value (thanks mitchcapper) + * OutlineThickness is corrected (OutlineThikness besfore, sorry for this breaking compatibility) + + + * v1.0 + + * First public release of the current implementation. + + + + diff --git a/Src/Bratched.Tools/RatingControl/IRateItemDefinition.cs b/Src/Bratched.Tools/RatingControl/IRateItemDefinition.cs index 5bb4ceb..cd3d36a 100644 --- a/Src/Bratched.Tools/RatingControl/IRateItemDefinition.cs +++ b/Src/Bratched.Tools/RatingControl/IRateItemDefinition.cs @@ -16,7 +16,7 @@ public interface IRateItemDefinition { SolidColorBrush BackgroundColor { get; set; } SolidColorBrush OutlineColor { get; set; } - object OutlineThikness { get; set; } + object OutlineThickness { get; set; } object PathData { get; set; } } } diff --git a/Src/Bratched.Tools/RatingControl/RateItem.xaml.cs b/Src/Bratched.Tools/RatingControl/RateItem.xaml.cs index f897f73..c68348d 100644 --- a/Src/Bratched.Tools/RatingControl/RateItem.xaml.cs +++ b/Src/Bratched.Tools/RatingControl/RateItem.xaml.cs @@ -34,8 +34,8 @@ public RateItem() private SolidColorBrush _emptyBackgroundColor; private SolidColorBrush _fullOutlineColor; private SolidColorBrush _emptyOutlineColor; - private double _fullOutlineThikness; - private double _emptyOutlineThikness; + private double _fullOutlineThickness; + private double _emptyOutlineThickness; private string _fullPathData; private string _emptyPathData; /// @@ -106,12 +106,12 @@ public SolidColorBrush EmptyOutlineColor /// /// Outline stroke thikness of the full rate item /// - public double FullOutlineThikness + public double FullOutlineThickness { - get { return _fullOutlineThikness; } + get { return _fullOutlineThickness; } set { - _fullOutlineThikness = value; + _fullOutlineThickness = value; rateFull.StrokeThickness = value; } } @@ -119,12 +119,12 @@ public double FullOutlineThikness /// /// Outline stroke thikness of the empty rate item /// - public double EmptyOutlineThikness + public double EmptyOutlineThickness { - get { return _emptyOutlineThikness; } + get { return _emptyOutlineThickness; } set { - _emptyOutlineThikness = value; + _emptyOutlineThickness = value; rateEmpty.StrokeThickness = value; } } @@ -197,12 +197,12 @@ private static Geometry StringToPath(string pathData) // (d as RateItem).rateEmpty.Stroke = (SolidColorBrush)e.NewValue; //} - //private static void FullOutlineThiknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + //private static void FullOutlineThicknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) //{ // (d as RateItem).rateFull.StrokeThickness = (double)e.NewValue; //} - //private static void EmptyOutlineThiknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + //private static void EmptyOutlineThicknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) //{ // (d as RateItem).rateEmpty.StrokeThickness = (double)e.NewValue; //} @@ -237,13 +237,13 @@ private static Geometry StringToPath(string pathData) // DependencyProperty.Register("FullOutlineColor", typeof(SolidColorBrush), typeof(RateItem), // new PropertyMetadata(null, FullOutlineColorChanged)); - //public static readonly DependencyProperty FullOutlineThiknessProperty = - // DependencyProperty.Register("FullOutlineThikness", typeof(double), typeof(RateItem), - // new PropertyMetadata(null, FullOutlineThiknessChanged)); + //public static readonly DependencyProperty FullOutlineThicknessProperty = + // DependencyProperty.Register("FullOutlineThickness", typeof(double), typeof(RateItem), + // new PropertyMetadata(null, FullOutlineThicknessChanged)); - //public static readonly DependencyProperty EmptyOutlineThiknessProperty = - // DependencyProperty.Register("EmptyOutlineThikness", typeof(double), typeof(RateItem), - // new PropertyMetadata(null, EmptyOutlineThiknessChanged)); + //public static readonly DependencyProperty EmptyOutlineThicknessProperty = + // DependencyProperty.Register("EmptyOutlineThickness", typeof(double), typeof(RateItem), + // new PropertyMetadata(null, EmptyOutlineThicknessChanged)); //public static readonly DependencyProperty FullPathDataProperty = // DependencyProperty.Register("FullPathData", typeof(string), typeof(RateItem), diff --git a/Src/Bratched.Tools/RatingControl/RateItemDefinition.cs b/Src/Bratched.Tools/RatingControl/RateItemDefinition.cs index 0f60249..e76446d 100644 --- a/Src/Bratched.Tools/RatingControl/RateItemDefinition.cs +++ b/Src/Bratched.Tools/RatingControl/RateItemDefinition.cs @@ -49,10 +49,10 @@ public SolidColorBrush OutlineColor /// /// Outline thikness for the rate Item /// - public object OutlineThikness + public object OutlineThickness { - get { return GetValue(OutlineThiknessProperty); } - set { SetValue(OutlineThiknessProperty, value); } + get { return GetValue(OutlineThicknessProperty); } + set { SetValue(OutlineThicknessProperty, value); } } /// @@ -87,15 +87,15 @@ private static void AspectChanged2(DependencyObject d, DependencyPropertyChanged } /// - /// Generate event change for OutlineThiknessProperty and redraw RatingControl + /// Generate event change for OutlineThicknessProperty and redraw RatingControl /// /// define rate element /// value property event - private static void OutlineThiknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private static void OutlineThicknessChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue is Binding && ParentRatingControl != null) - BindingOperations.SetBinding(d, OutlineThiknessProperty, (Binding)e.NewValue); + BindingOperations.SetBinding(d, OutlineThicknessProperty, (Binding)e.NewValue); if (e.OldValue != e.NewValue && ParentRatingControl != null) ParentRatingControl.GenerateItems(); } @@ -122,17 +122,17 @@ private static void PathDataChanged(DependencyObject d, DependencyPropertyChange DependencyProperty.RegisterAttached("OutlineColor", typeof(SolidColorBrush), typeof(RateItemDefinition), new PropertyMetadata(null, AspectChanged2)); - // public static readonly DependencyProperty OutlineThiknessProperty = - // DependencyProperty.Register("OutlineThikness", typeof(object), typeof(RatingControl), - // new PropertyMetadata(null, OutlineThiknessChanged)); + // public static readonly DependencyProperty OutlineThicknessProperty = + // DependencyProperty.Register("OutlineThickness", typeof(object), typeof(RatingControl), + // new PropertyMetadata(null, OutlineThicknessChanged)); // public static readonly DependencyProperty PathDataProperty = // DependencyProperty.RegisterAttached("PathData", typeof(object), typeof(RatingControl), // new PropertyMetadata(null, PathDataChanged)); - public static readonly DependencyProperty OutlineThiknessProperty = - DependencyProperty.Register("OutlineThikness", typeof(object), typeof(RateItemDefinition), - new PropertyMetadata(null, OutlineThiknessChanged)); + public static readonly DependencyProperty OutlineThicknessProperty = + DependencyProperty.Register("OutlineThickness", typeof(object), typeof(RateItemDefinition), + new PropertyMetadata(null, OutlineThicknessChanged)); public static readonly DependencyProperty PathDataProperty = DependencyProperty.RegisterAttached("PathData", typeof(object), typeof(RateItemDefinition), diff --git a/Src/Bratched.Tools/RatingControl/RateItemDefinitionModel.cs b/Src/Bratched.Tools/RatingControl/RateItemDefinitionModel.cs index 5abd4b1..b9f3096 100644 --- a/Src/Bratched.Tools/RatingControl/RateItemDefinitionModel.cs +++ b/Src/Bratched.Tools/RatingControl/RateItemDefinitionModel.cs @@ -17,7 +17,7 @@ public sealed class RateItemDefinitionModel: IRateItemDefinition { public SolidColorBrush BackgroundColor { get; set; } public SolidColorBrush OutlineColor { get;set; } - public object OutlineThikness { get; set; } + public object OutlineThickness { get; set; } public object PathData { get; set; } } diff --git a/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs b/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs index e2dec12..2416bf4 100644 --- a/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs +++ b/Src/Bratched.Tools/RatingControl/RatingControl.xaml.cs @@ -26,8 +26,7 @@ public enum DefinitionCycles { Repeat, Linear } public partial class RatingControl : UserControl { - private const bool DEBUG_MODE = false; - + private const bool DEBUG_MODE = false; public RatingControl() { EmptyItemsDefinition = new List(); @@ -51,13 +50,14 @@ public RatingControl() InitDefaultValues(); } - + private void ChangeItemsValue(double x) { if (rateItems.Children.Any()) Value = RoundSliced(x * ItemsCount / rateItems.ActualWidth); - System.Diagnostics.Debug.WriteLine(String.Format("X={2}, New Value {0}, ActualWidth {1}, ", Value, rateItems.ActualWidth, x)); + if (DEBUG_MODE) + System.Diagnostics.Debug.WriteLine(String.Format("X={2}, New Value {0}, ActualWidth {1}, ", Value, rateItems.ActualWidth, x)); } #if NETFX_CORE @@ -98,6 +98,7 @@ private void InitDefaultValues() Margin = new Thickness(0); Background = new SolidColorBrush(Colors.Transparent); IsEditable = false; + AllowHover = true; Value = 0; } @@ -263,14 +264,14 @@ private double GenerateRateItem(double localValue, List def IRateItemDefinition fullItemDefinition = GetDefinitionFromIndex(FullItemsDefinition, i); item.FullBackgroundColor = fullItemDefinition != null && fullItemDefinition.BackgroundColor != null ? fullItemDefinition.BackgroundColor : fullDefaultDefinition.BackgroundColor; item.FullOutlineColor = fullItemDefinition != null && fullItemDefinition.OutlineColor != null ? fullItemDefinition.OutlineColor : fullDefaultDefinition.OutlineColor; - item.FullOutlineThikness = fullItemDefinition != null && fullItemDefinition.OutlineThikness is Double ? Convert.ToDouble(fullItemDefinition.OutlineThikness) : Convert.ToDouble(fullDefaultDefinition.OutlineThikness); + item.FullOutlineThickness = fullItemDefinition != null && fullItemDefinition.OutlineThickness is Double ? Convert.ToDouble(fullItemDefinition.OutlineThickness) : Convert.ToDouble(fullDefaultDefinition.OutlineThickness); item.FullPathData = fullItemDefinition != null && fullItemDefinition.PathData is String ? Convert.ToString(fullItemDefinition.PathData) : Convert.ToString(fullDefaultDefinition.PathData); IRateItemDefinition emptyDefaultDefinition = GetDefinitionFromIndex(defaultEmpty, i); IRateItemDefinition emptyItemDefinition = GetDefinitionFromIndex(EmptyItemsDefinition, i); item.EmptyBackgroundColor = emptyItemDefinition != null && emptyItemDefinition.BackgroundColor != null ? emptyItemDefinition.BackgroundColor : emptyDefaultDefinition.BackgroundColor; item.EmptyOutlineColor = emptyItemDefinition != null && emptyItemDefinition.OutlineColor != null ? emptyItemDefinition.OutlineColor : emptyDefaultDefinition.OutlineColor; - item.EmptyOutlineThikness = emptyItemDefinition != null && emptyItemDefinition.OutlineThikness is Double ? Convert.ToDouble(emptyItemDefinition.OutlineThikness) : Convert.ToDouble(emptyDefaultDefinition.OutlineThikness); + item.EmptyOutlineThickness = emptyItemDefinition != null && emptyItemDefinition.OutlineThickness is Double ? Convert.ToDouble(emptyItemDefinition.OutlineThickness) : Convert.ToDouble(emptyDefaultDefinition.OutlineThickness); item.EmptyPathData = emptyItemDefinition != null && emptyItemDefinition.PathData is String ? Convert.ToString(emptyItemDefinition.PathData) : Convert.ToString(emptyDefaultDefinition.PathData); if (localValue > 1) @@ -306,14 +307,14 @@ private void InitTemplateLike(List defaultFull, List defaultFull, List defaultFull, List defaultFull, List defaultFull, List defaultFull, List defaultFull, List defaultFull, List defaultFull, List defaultFull, List /// return RoundValue of Value if RoundValueSlice > 0 @@ -461,6 +466,8 @@ public double RoundValue 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), @@ -517,7 +524,7 @@ private static void EmptyItemsDefinitionCallback(DependencyObject d, DependencyP private static void ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { - RatingControl control = (d as RatingControl); + RatingControl control = (d as RatingControl); if (control._isLoaded) { control.RefreshRateValues(); @@ -550,9 +557,10 @@ 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; + 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) @@ -578,9 +586,10 @@ private void GridCaptureMovement_ManipulationDelta(object sender, ManipulationDe #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; + if (DEBUG_MODE) System.Diagnostics.Debug.WriteLine("ManipulationDelta {0} - {1}", DateTime.Now, e.ManipulationOrigin.X); double x = e.ManipulationOrigin.X; ChangeItemsValue(x); @@ -596,6 +605,7 @@ void RatingControl_MouseLeftButtonDown(object sender, System.Windows.Input.Mouse if (p != null) { ChangeItemsValue(p.X); + if (DEBUG_MODE) System.Diagnostics.Debug.WriteLine("PointerMoved {0} - {1}", DateTime.Now, p.X); } }