I’ve been trying to make my textboxes in my DataGrid wrap. I got it working but it seems to break the Text binding.
XAML
<DataGrid x:Name="dataGrid" Grid.Row="0" AutoGenerateColumns="False" ItemsSource="{Binding}">
<!-- <DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<TextBox TextWrapping="Wrap" Text="{Binding Path=Value}">
</TextBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.CellStyle> -->
</DataGrid>
I add the columns and rows using a data set like so.
CS
#region Variables
private DataTable m_stringData = new DataTable();
private DataSet m_stringDataSet = new DataSet();
#endregion
#region Constructors
public LocEditor()
{
InitializeComponent();
AddColumn("ID", 100);
AddString("Test");
dataGrid.DataContext = m_stringData;
}
#endregion
#region Methods
private void AddColumn(string l_columnName, int l_iWidth)
{
m_stringData.Columns.Add(l_columnName, typeof(string));
dataGrid.Columns.Add(new DataGridTextColumn
{
Header = l_columnName,
Width = l_iWidth,
Binding = new Binding(l_columnName)
//Binding = new Binding(string.Format("[{0}]", l_columnName))
});
}
private void AddString(string l_stringID)
{
m_stringData.Rows.Add();
m_stringData.Rows[m_stringData.Rows.Count - 1][0] = l_stringID;
}
#endregion
Any help would be greatly appreciated.
Figured it out. By setting the Element and EditingElementStyle, I don’t have to reset the Binding.