我试图向这样的列添加进度条
<DataGrid Grid.Row="1" ItemsSource="{Binding Locations}" AutoGenerateColumns="false">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Plant}" Header="Plant" />
<DataGridTextColumn Binding="{Binding Area}" Header="Area" />
<DataGridTextColumn Binding="{Binding LocationName}" Header="Location" />
<DataGridTextColumn Binding="{Binding LocationVersion}" Header="Version on location" />
<DataGridCheckBoxColumn Binding="{Binding Deploy, Mode=TwoWay}" Header="Check to deploy" IsReadOnly="False" />
<DataGridTemplateColumn Header="Orders Count" Width="380">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ProgressBar Grid.Row="0" Grid.Column="0" Minimum="0" Maximum="200" Value="{Binding copyToLocationProgress ,Mode=OneWay}"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
这是我正在使用的 ILocation:
public interface ILocation
{
int LocationId { get; }
string LocationName { get; set; }
string Area { get; set; }
string LocationVersion { get; set; }
int Plant { get; set; }
bool Deploy { get; set; }
string FolderName { get; }
int copyToLocationProgress { get; set; }
}
这是在 ViewModel 中
public IEnumerable<ILocation> Locations { get; set; }
我也试过这种方式
<DataGridTemplateColumn Header="Deploy progress" Width="380">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ProgressBar
Grid.Row="0"
Grid.Column="0"
Minimum="0"
Maximum="200"
Value="{Binding Path=DataContext.Locations, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
但这给了我这个错误:
System.Windows.Data 错误:5:BindingExpression 生成的值对目标属性无效。;值=''绑定表达式:路径=DataContext.Locations;DataItem='DataGrid' (名称=''); 目标元素是'ProgressBar'(名称='');目标属性是“值”(类型“双”)
但我看不到其他列上的值。因为它是数据绑定到网格的。