我正在显示绑定到DataTable的DataGrid:
我的问题是,在每一行的第一列的值上,文本都被剪切了。
我不确定这是因为列的宽度太短(看起来不是)还是出于其他原因。
首先我想知道为什么会这样吗?
第二,有没有办法通过代码动态设置每一列的宽度?
如您所见,“ Alfred Hitchcock”显示为“ Alfred Hitchco”
这是xaml:
<DataGrid x:Name="_dataGrid"
IsHitTestVisible="False"
Background="Transparent"
Margin="20"
CanUserAddRows="False"
CanUserDeleteRows="False"
IsReadOnly="True"
ItemsSource="{Binding StatisticsDataTableView}"
HorizontalContentAlignment="Left" VerticalContentAlignment="Bottom" HorizontalAlignment="Center" VerticalAlignment="Center">
以下是属性:
public DataView StatisticsDataTableView
{
get { return _statisticsDataTableView; }
set
{
_statisticsDataTableView = value;
OnPropertyChanged();
}
}
然后在代码中像这样动态创建表:
_dataTable = new DataTable();
var column = _dataTable.Columns.Add("Sprints:");
foreach (var sprint in Plan.Sprints)
{
_dataTable.Columns.Add(sprint.SprintNumber.ToString());
}
List<string> sinsglePerformers = new List<string>();
foreach (var performer in _settings.Performers)
{
if (performer.Name == "All" || performer.Name == "Unassigned" || !performer.IsEnabled)
{
continue;
}
var splitedPerformers = performer.Name.Split(',');
for (int i = 0; i < splitedPerformers.Length; i++)
{
if (!sinsglePerformers.Contains(splitedPerformers[i]))
{
sinsglePerformers.Add(splitedPerformers[i]);
}
}
}
foreach (var performer in sinsglePerformers)
{
var newRow = _dataTable.NewRow();
_dataTable.Rows.Add(newRow);
newRow[0] = performer;
int sprintIndex = 1;
foreach (var jaraSprint in Plan.Sprints)
{
var tasks = jaraSprint.Tasks.Where(t => t.Performers.Any(p => p.Name == performer));
double days = tasks.Sum(jaraTask => jaraTask.TimeInDays);
newRow[sprintIndex] = $"{days*100/(_plan.WeeksInSprint*5):0.}" + "%";
sprintIndex++;
}
}
StatisticsDataTableView = _dataTable.AsDataView();
有什么想法吗?