Skip to content

Commit

Permalink
WPF0006: Name of CoerceValueCallback should match registered name.
Browse files Browse the repository at this point in the history
WPF0007: Name of ValidateValueCallback should match registered name.
  • Loading branch information
punker76 committed Feb 4, 2018
1 parent 4996db8 commit 1c3bfe7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
@@ -1,45 +1,55 @@
using System.Windows;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;

namespace MahApps.Metro.Controls
{
using System.ComponentModel;

/// <summary>
/// A helper class that provides various attached properties for the ComboBox control.
/// <see cref="ComboBox"/>
/// A helper class that provides various attached properties for the <see cref="ComboBox"/> control.
/// </summary>
public class ComboBoxHelper
{
public static readonly DependencyProperty EnableVirtualizationWithGroupingProperty = DependencyProperty.RegisterAttached("EnableVirtualizationWithGrouping", typeof(bool), typeof(ComboBoxHelper), new FrameworkPropertyMetadata(false, EnableVirtualizationWithGroupingPropertyChangedCallback));
public static readonly DependencyProperty EnableVirtualizationWithGroupingProperty
= DependencyProperty.RegisterAttached("EnableVirtualizationWithGrouping",
typeof(bool),
typeof(ComboBoxHelper),
new FrameworkPropertyMetadata(false, OnEnableVirtualizationWithGroupingChanged));

private static void EnableVirtualizationWithGroupingPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
private static void OnEnableVirtualizationWithGroupingChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
var comboBox = dependencyObject as ComboBox;
if (comboBox != null && e.NewValue != e.OldValue)
{
#if NET4_5
comboBox.SetValue(VirtualizingStackPanel.IsVirtualizingProperty, e.NewValue);
comboBox.SetValue(VirtualizingPanel.IsVirtualizingWhenGroupingProperty, e.NewValue);
comboBox.SetValue(ScrollViewer.CanContentScrollProperty, e.NewValue);
comboBox.SetCurrentValue(VirtualizingStackPanel.IsVirtualizingProperty, e.NewValue);
comboBox.SetCurrentValue(VirtualizingPanel.IsVirtualizingWhenGroupingProperty, e.NewValue);
comboBox.SetCurrentValue(ScrollViewer.CanContentScrollProperty, e.NewValue);
#endif
}
}

[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
public static void SetEnableVirtualizationWithGrouping(DependencyObject obj, bool value)
{
obj.SetValue(EnableVirtualizationWithGroupingProperty, value);
}

[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
public static bool GetEnableVirtualizationWithGrouping(DependencyObject obj)
{
return (bool)obj.GetValue(EnableVirtualizationWithGroupingProperty);
}

public static readonly DependencyProperty MaxLengthProperty = DependencyProperty.RegisterAttached("MaxLength", typeof(int), typeof(ComboBoxHelper), new FrameworkPropertyMetadata(0), new ValidateValueCallback(MaxLengthValidateValue));
public static readonly DependencyProperty MaxLengthProperty
= DependencyProperty.RegisterAttached("MaxLength",
typeof(int),
typeof(ComboBoxHelper),
new FrameworkPropertyMetadata(0),
ValidateMaxLength);

private static bool MaxLengthValidateValue(object value)
private static bool ValidateMaxLength(object value)
{
return ((int)value) >= 0;
}
Expand All @@ -57,14 +67,21 @@ public static int GetMaxLength(UIElement obj)
/// <summary>
/// Sets the Maximum number of characters the TextBox can accept.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
public static void SetMaxLength(UIElement obj, int value)
{
obj.SetValue(MaxLengthProperty, value);
}

public static readonly DependencyProperty CharacterCasingProperty = DependencyProperty.RegisterAttached("CharacterCasing", typeof(CharacterCasing), typeof(ComboBoxHelper), new FrameworkPropertyMetadata(CharacterCasing.Normal), new ValidateValueCallback(CharacterCasingValidateValue));
public static readonly DependencyProperty CharacterCasingProperty
= DependencyProperty.RegisterAttached("CharacterCasing",
typeof(CharacterCasing),
typeof(ComboBoxHelper),
new FrameworkPropertyMetadata(CharacterCasing.Normal),
ValidateCharacterCasing);

private static bool CharacterCasingValidateValue(object value)
private static bool ValidateCharacterCasing(object value)
{
return (CharacterCasing.Normal <= (CharacterCasing)value && (CharacterCasing)value <= CharacterCasing.Upper);
}
Expand All @@ -82,9 +99,11 @@ public static CharacterCasing GetCharacterCasing(UIElement obj)
/// <summary>
/// Sets the Character casing of the TextBox.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
public static void SetCharacterCasing(UIElement obj, CharacterCasing value)
{
obj.SetValue(CharacterCasingProperty, value);
}
}
}
}
28 changes: 11 additions & 17 deletions src/MahApps.Metro/MahApps.Metro.Shared/Controls/RangeSlider.cs
Expand Up @@ -1938,16 +1938,6 @@ private void RelocateAutoToolTip()
_autoToolTip.HorizontalOffset = offset;
}

private static bool IsValidDoubleValue(object value)
{
return value is double && IsValidDouble((double)value);
}

private static bool IsValidDouble(double d)
{
return !double.IsNaN(d) && !double.IsInfinity(d);
}

//CHeck if two doubles approximately equals
private bool ApproximatelyEquals(double value1, double value2)
{
Expand Down Expand Up @@ -2024,20 +2014,24 @@ private CustomPopupPlacement[] PopupPlacementCallback(Size popupSize, Size targe

#region Validation methods

private static bool IsValidDoubleValue(object value)
{
return value is double && IsValidDouble((double)value);
}

private static bool IsValidDouble(double d)
{
return !double.IsNaN(d) && !double.IsInfinity(d);
}

private static bool IsValidPrecision(object value)
{
return ((Int32)value >= 0);
}

private static bool IsValidMinRange(object value)
{
double d = (double)value;
if (!Double.IsNaN(d))
{
return d >= 0d || !double.IsInfinity(d);
}

return false;
return value is double && IsValidDouble((double)value) && (double)value >= 0d;
}

#endregion
Expand Down
3 changes: 3 additions & 0 deletions src/MahApps.Metro/MahApps.Metro/Properties/AssemblyInfo.cs
Expand Up @@ -19,3 +19,6 @@
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyInformationalVersion("1.6.0.0")]
[assembly: AssemblyProduct("MahApps.Metro 1.6.0")]

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("WpfAnalyzers.DependencyProperty", "WPF0006:Name of CoerceValueCallback should match registered name.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("WpfAnalyzers.DependencyProperty", "WPF0007:Name of ValidateValueCallback should match registered name.")]

0 comments on commit 1c3bfe7

Please sign in to comment.