是否有办法自动将所有(或特定列)输入大写到WPF Datagrid。 当我输入datagrid的单元格并按Enter键时,我需要单元格中的所有文本都成为大写。
答案 0 :(得分:6)
试试这个
<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; }
}