Reputation: 1886
Is there a way to automatically capitalize all (or to specific column) input to WPF Datagrid. When I type to datagrid's cell and press Enter I need all the text in cell to become of upper case.
Upvotes: 3
Views: 3406
Reputation: 8273
Try this
<DataGrid ItemsSource="{Binding MyList}"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Test Character Casing"
Binding="{Binding Name}">
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="TextBox">
<Setter Property="CharacterCasing" Value="Upper"/>
</Style>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MyList = new List<MyItem>();
MyList.Add(new MyItem { Name = "" });
MyList.Add(new MyItem { Name = "" });
this.DataContext = this;
}
public List<MyItem> MyList { get; set; }
}
public class MyItem
{
public string Name { get; set; }
}
Upvotes: 9