Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 new attached properties for ComboBoxHelper #1949

Merged
merged 1 commit into from
Jun 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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