public void LoadDetail() { Application.Current.Dispatcher.Invoke(() => { var Listado = new List <string>(); string strOutMessageError = string.Empty; CmpTask.ProcessAsync(() => { IdCategoria = (ObjEMNF_ArticuloCategoria != null) ? Convert.ToString(ObjEMNF_ArticuloCategoria.IdCategoria) : string.Empty; IdSubCategoria = (ObjEMNF_ArticuloSubCategoria != null) ? Convert.ToString(ObjEMNF_ArticuloSubCategoria.IdSubCategoria) : string.Empty; IdMarca = (ObjEMNF_ArticuloMarca != null) ? Convert.ToString(ObjEMNF_ArticuloMarca.IdMarca) : string.Empty; IdArticulo = (ObjEMNF_Articulo != null) ? Convert.ToString(ObjEMNF_Articulo.IdArticulo) : "0"; IdProveedor = (ObjEMNF_ClienteProveedor != null) ? Convert.ToString(ObjEMNF_ClienteProveedor.IdCliProveedor) : "0"; Listado = new BCMP_TempArticuloListaPrecio().ListArticuloListaPercio(IdCategoria, IdSubCategoria, IdMarca, IdArticulo, IdProveedor, FechaDesde.ToString("yyyyMM"), FechaHasta.ToString("yyyyMM")); }, (e) => { if (e != null) { CmpMessageBox.Show(CMPMensajes.TitleAdminListadoPrecio, e.Message, CmpButton.Aceptar); return; } if (Listado == null) { dtgListaPrecio.Columns.Clear(); return; } dtgListaPrecio.Columns.Clear(); var vrObjStringColumn = Listado.FirstOrDefault(); string[] arrayNamaColumn = vrObjStringColumn.Split("/".ToCharArray()); arrayNamaColumn = arrayNamaColumn.Where(x => x != "").ToArray(); int Index = 0; foreach (var name in arrayNamaColumn) { FrameworkElementFactory TextFActory = new FrameworkElementFactory(typeof(TextBlock)); DataTemplate dataTemp = new DataTemplate(); DataGridTemplateColumn tempColumn = new DataGridTemplateColumn(); tempColumn.Header = name; Binding bing = new Binding("[" + Index + "]"); bing.Mode = BindingMode.TwoWay; TextFActory.SetBinding(TextBlock.TextProperty, bing); if (Index > 8) { if (TextFActory.Type.Equals(typeof(TextBlock))) { TextFActory.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Right); } tempColumn.MinWidth = 100; tempColumn.Width = new DataGridLength(1, DataGridLengthUnitType.Star); } dataTemp.VisualTree = TextFActory; tempColumn.CellTemplate = dataTemp; tempColumn.IsReadOnly = true; dtgListaPrecio.Columns.Add(tempColumn); Index++; } dtgListaPrecio.Columns[0].MinWidth = 75; dtgListaPrecio.Columns[1].MinWidth = 200; dtgListaPrecio.Columns[1].MinWidth = 300; dtgListaPrecio.Columns[2].MinWidth = 90; dtgListaPrecio.Columns[3].MinWidth = 120; dtgListaPrecio.Columns[4].MinWidth = 120; dtgListaPrecio.Columns[5].MinWidth = 120; dtgListaPrecio.Columns[6].MinWidth = 90; dtgListaPrecio.Columns[7].MinWidth = 300; dtgListaPrecio.Columns[7].Header = "Proveedor"; dtgListaPrecio.Columns[8].MinWidth = 70; //Agrega Valor Listado.RemoveAt(0); List <object> rows = new List <object>(); foreach (var value in Listado) { string[] arrayValueRow = value.Split(",".ToCharArray()); rows.Add(arrayValueRow); } dtgListaPrecio.ItemsSource = rows; lblCountItems.Text = dtgListaPrecio.Items.Count + " Registros"; }); }); }