WPF DataGrid ile çalışıyorum. Sütun Başlığını sürüklemeliyim, başka bir kontrole bırakmalıyım (Label) ve bazı işlemleri yapmalıyım. Ama DataGrid sütun üstbilgisi sürükle ve bırak elde edemiyorum. ColumnHeaderDragStarted olayı ile denedim, ancak sütun üstbilgisi nesnesini veya işleyicideki yalnızca başlığın adını bulamıyorum. Herhangi bir yardım plz !!DataGrid sütun başlığı nasıl sürüklenir ve bırakılır?
5
A
cevap
4
Belki bu size yardımcı olabilir: XAML üzerinde
:
< DataGrid Adı = "DataGrid" MouseRightButtonUp = "DataGrid_MouseRightButtonUp"/> C# Code üzerinde
:
private void DataGrid_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
while ((dep != null) && !(dep is DataGridCell) && !(dep is DataGridColumnHeader))
{
dep = VisualTreeHelper.GetParent(dep);
}
if (dep == null)
return;
if (dep is DataGridColumnHeader)
{
DataGridColumnHeader columnHeader = dep as DataGridColumnHeader;
// find the property that this cell's column is bound to
string boundPropertyName = FindBoundProperty(columnHeader.Column);
int columnIndex = columnHeader.Column.DisplayIndex;
ClickedItemDisplay.Text = string.Format(
"Header clicked [{0}] = {1}",
columnIndex, boundPropertyName);
}
if (dep is DataGridCell)
{
DataGridCell cell = dep as DataGridCell;
// navigate further up the tree
while ((dep != null) && !(dep is DataGridRow))
{
dep = VisualTreeHelper.GetParent(dep);
}
if (dep == null)
return;
DataGridRow row = dep as DataGridRow;
object value = ExtractBoundValue(row, cell);
int columnIndex = cell.Column.DisplayIndex;
int rowIndex = FindRowIndex(row);
ClickedItemDisplay.Text = string.Format(
"Cell clicked [{0}, {1}] = {2}",
rowIndex, columnIndex, value.ToString());
}
}
/// <summary>
/// Determine the index of a DataGridRow
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
private int FindRowIndex(DataGridRow row)
{
DataGrid dataGrid = ItemsControl.ItemsControlFromItemContainer(row) as DataGrid;
int index = dataGrid.ItemContainerGenerator.IndexFromContainer(row);
return index;
}
/// <summary>
/// Find the value that is bound to a DataGridCell
/// </summary>
/// <param name="row"></param>
/// <param name="cell"></param>
/// <returns></returns>
private object ExtractBoundValue(DataGridRow row, DataGridCell cell)
{
// find the property that this cell's column is bound to
string boundPropertyName = FindBoundProperty(cell.Column);
// find the object that is realted to this row
object data = row.Item;
// extract the property value
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(data);
PropertyDescriptor property = properties[boundPropertyName];
object value = property.GetValue(data);
return value;
}
/// <summary>
/// Find the name of the property which is bound to the given column
/// </summary>
/// <param name="col"></param>
/// <returns></returns>
private string FindBoundProperty(DataGridColumn col)
{
DataGridBoundColumn boundColumn = col as DataGridBoundColumn;
// find the property that this column is bound to
Binding binding = boundColumn.Binding as Binding;
string boundPropertyName = binding.Path.Path;
return boundPropertyName;
}
}
// This XAML and C# where extracted from a link contained on this URL:
// http://social.msdn.microsoft.com/Forums/en/wpf/thread/61707b8a-e6c6-474b-ac2b-3446319625bd
İlgili konular
- 1. MahApps DataGrid sütun başlığı kasası
- 2. WPF: Datagrid'de sütun başlığı nasıl dondurulur?
- 3. WPF DataGrid'de sütun başlığı nasıl gizlenir?
- 4. DataGrid Düğmesi Sütun Görünmüyor
- 5. WPF DataGrid Sütun Genişliği
- 6. WPF Datagrid bağlacı ve sütun gösterimi
- 7. Force DataGrid sütun doğrulaması (WPF)
- 8. JQGrid set başlığı ve sütun adı
- 9. DataGrid bir sütun içeriyorsa nasıl bulunur?
- 10. wpf DataGrid sütun genişliği, ListBox
- 11. StringGrid sütun başlığı yüksekliği ayarlama
- 12. Panelin etrafında kontrol nasıl sürüklenir?
- 13. ASP.NET'teki çoklu sütun başlığı GridView
- 14. Başlık metni dinamik olarak oluşturulduğu bir datagrid başlığı için bir araç ipucu nasıl eklenir?
- 15. WPF DataGrid Düğmesi Sütun Devre Dışı Bırakma
- 16. WPF DataGrid Sütun Genişliği Otomatik ve Kaydırma Çubuğu
- 17. WPF4 Datagrid sütun başlıkları üzerinde sıralanmaz
- 18. GWT 2.1 CellTable Sütun Başlığı Click olayları
- 19. Bağlantılar/sayfalar jQuery eklentisi aracılığıyla nasıl sürüklenir?
- 20. Datagrid: Footer
- 21. Ruby ile bir csv dosyasına sütun başlığı nasıl yazılır?
- 22. Python kullanarak sütun başlığı olarak kullanılan metinler nasıl atlanır
- 23. WPF DataGrid stili-Silverlight DataGrid?
- 24. Hazırda bekletme - Bir sütun için eşleme nasıl devre dışı bırakılır
- 25. DataGrid
- 26. Codebehind öğesindeki ITemplate ve DataGrid Sütunu
- 27. DataGrid nasıl şeffaf yapılır?
- 28. Sütun ve hesaplanan sütun nasıl değiştirilir
- 29. ASP.NET datagrid nasıl temizlenir?
- 30. WPF DataGrid