We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change casing of line items in EditControl?

Platform: WPF |
Control: EditControl |
.NET Framework: 4

EditControl provides option for an end user to customize the Character casing of its contents. Please follow below steps for achieving this.

 

Step 1: At present there is no property in EditControl, to define Character casing for its contents. So here we are creating Custom control, derived from the EditControl and implemented property to define the Character casing.

Step 2: In EditControl, Lines property will hold its contents i.e. line by line. On the drawing process, each line will be retrieved from this collection and drawn in EditControl UI.

Step 3: Here we are iterating each line and apply the Character casing to it. Then it will be reflected in EditControl with Character case settings.

The following code demonstrates the same.

 

Code Example: [Xaml]

 

<!--MenuAdv-->
 
<syncfusion:MenuAdv Grid.Row="0"  syncfusion:SkinStorage.VisualStyle="Blend" >
 
<syncfusion:MenuItemAdv Header="Lower case" Click="MenuItemAdv_Click"/>
 
<syncfusion:MenuItemAdv Header="Upper case" Click="MenuItemAdv_Click_1"/>
 
<syncfusion:MenuItemAdv Header="Default" Click="MenuItemAdv_Click_2"/>
 
</syncfusion:MenuAdv>
 
<!--EditControl-->
 
<syncfusion:EditControl x:Name="editcontrol" Grid.Row="1" Focusable="True"/>
 

 

Code Example: [C#]

 

//Codes in MainWindow.xaml.cs
 
editcontrol.KeyUp += Editcontrol_KeyUp;
 
editcontrol.TextChanged += Editcontrol_TextChanged;
 
private void Editcontrol_TextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
 
if (EditControlExt.GetCharacterCasing(editcontrol) == EditControlExt.CharacterCasing.Upper)
{
 
SetUpperCaseText();
 
}
 
else if (EditControlExt.GetCharacterCasing(editcontrol)==EditControlExt.CharacterCasing.Lower)
{
 
SetLowerCaseText();
 
}
 
}
 
private void Editcontrol_KeyUp(object sender, KeyEventArgs e)
{
 
if (EditControlExt.GetCharacterCasing(editcontrol) == EditControlExt.CharacterCasing.Upper)
{
 
SetUpperCaseText();
 
}
 
else if (EditControlExt.GetCharacterCasing(editcontrol)==EditControlExt.CharacterCasing.Lower)
{
 
SetLowerCaseText();
 
}
}
 
private void SetUpperCaseText()
{
 
for (int i = 0; i <= editcontrol.Lines.Count-1; i++)
{
 
editcontrol.Lines[i].Text = editcontrol.Lines[i].Text.ToUpper();
 
}
}
 
private void SetLowerCaseText()
{
 
for (int i = 0; i <= editcontrol.Lines.Count-1; i++)
{
 
editcontrol.Lines[i].Text = editcontrol.Lines[i].Text.ToLower();
 
}
}
 
//Set Lower case 
EditControlExt.SetCharacterCasing(editcontrol, EditControlExt.CharacterCasing.Lower);
 
//Set Upper case 
 
EditControlExt.SetCharacterCasing(editcontrol, EditControlExt.CharacterCasing.Upper);
 
//Set Default/Normal case
 
EditControlExt.SetCharacterCasing(editcontrol, EditControlExt.CharacterCasing.Normal);
 
 
//Codes in EditControlExt.cs
 
//CharacterCasing property
 
public class EditControlExt
{
 
public enum CharacterCasing
{
 
Upper,
Lower,
Normal,
 
}
 
 
public static CharacterCasing GetCharacterCasing(DependencyObject obj)
{
 
return (CharacterCasing)obj.GetValue(CharacterCasingProperty);
 
}
 
public static void SetCharacterCasing(DependencyObject obj, CharacterCasing value)
{
 
obj.SetValue(CharacterCasingProperty, value);
 
}
 
// Using a DependencyProperty as the backing store for CharacterCasing.
public static readonly DependencyProperty CharacterCasingProperty =
 
DependencyProperty.RegisterAttached("CharacterCasing", typeof(CharacterCasing), 
 
typeof(EditControlExt), new PropertyMetadata(CharacterCasing.Normal));
 
}
 

 

Screenshot

 

wpf edit control character casing is lower

Figure:  CharacterCasing is lower.

 

 

wpf edit control character casing is upper

Figure:  CharacterCasing is upper.

 

 

wpf edit control character casing is normal

Figure:  CharacterCasing is Normal.

 

Sample:  EditControlCharacterCasingSample

 

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile