Skip to content

Commit

Permalink
Merge pull request #1949 from MahApps/1948-ComboBox-TextBox-DepProp-h…
Browse files Browse the repository at this point in the history
…elper

2 new attached properties for ComboBoxHelper
  • Loading branch information
punker76 committed Jun 1, 2015
2 parents 21a04f4 + dcf9a98 commit c6949c3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions MahApps.Metro/Controls/Helper/ComboBoxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,51 @@ 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));

private static bool MaxLengthValidateValue(object value)
{
return ((int)value) >= 0;
}

/// <summary>
/// Gets the Maximum number of characters the TextBox can accept.
/// </summary>
public static int GetMaxLength(UIElement obj)
{
return (int)obj.GetValue(MaxLengthProperty);
}

/// <summary>
/// Sets the Maximum number of characters the TextBox can accept.
/// </summary>
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));

private static bool CharacterCasingValidateValue(object value)
{
return (CharacterCasing.Normal <= (CharacterCasing)value && (CharacterCasing)value <= CharacterCasing.Upper);
}

/// <summary>
/// Gets the Character casing of the TextBox.
/// </summary>
public static CharacterCasing GetCharacterCasing(UIElement obj)
{
return (CharacterCasing)obj.GetValue(CharacterCasingProperty);
}

/// <summary>
/// Sets the Character casing of the TextBox.
/// </summary>
public static void SetCharacterCasing(UIElement obj, CharacterCasing value)
{
obj.SetValue(CharacterCasingProperty, value);
}
}
}
2 changes: 2 additions & 0 deletions MahApps.Metro/Styles/Controls.ComboBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@
Background="{x:Null}"
Margin="0,0,0,-2"
Controls:TextBoxHelper.Watermark="{TemplateBinding Controls:TextBoxHelper.Watermark}"
MaxLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ComboBoxHelper.MaxLength), Mode=OneWay}"
CharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ComboBoxHelper.CharacterCasing), Mode=OneWay}"
Foreground="{TemplateBinding Foreground}"
Focusable="True"
IsReadOnly="{TemplateBinding IsReadOnly}"
Expand Down

0 comments on commit c6949c3

Please sign in to comment.