In the WPF using MVVM approach with command pattern. Accordingly to it. you need to have View and ViewModel then you will be able to use command for the Download button in your grid and pass parameter to it.
public class ClientsViewModel : INotifyPropertyChanged
{
public DelegateCommand DownloadCommand {get; private set;}
// ctor
public ClientsVM()
{
DownloadCommand = new DelegateCommand(DownloadExecute));
}
// async method allow to not block UI thread
public async void DownloadExecute(object param)
{
var client = param as Clients;
if (client==null) return;
// TODO: call real code for download
for (int i=0; i<100; i++)
{
await Task.Delay(100); // slow changes of progress
client.Progress = i; // if setter of Progress raised NotifyPropertyChanged.. it will update ProgressBar in your DataGrid
}
}
}
To use your DownloadCommand just bind it to the property of Button
<DataGrid AutoGenerateColumns="False" x:Name="servers" HorizontalAlignment="Center" Height="148" Margin="0,78,0,0" VerticalAlignment="Top" Width="772" PreviewMouseDoubleClick="clientPreview">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" IsReadOnly="True" Binding="{Binding Id}" Width="50"></DataGridTextColumn>
<DataGridTemplateColumn Header="Progress"
Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ProgressBar
Value="{Binding Progress}"
Minimum="0" Maximum="100" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Action" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<Button Background="#FF00FF35" Command="{Binding DownloadCommand, Mode=OneWay}" CommandParameter="{Binding}">Download</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>