DataGrid'inizin DataGridColumnHeadersPresenter'unu almanız ve ContextMenu'nu ayarlamanız yeterlidir.
public static class Visual_ExtensionMethods
{
/// <summary>
/// Retrieves the first Descendant of the currren Visual in the VisualTree matching the given predicate
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="this">The current Visual.</param>
/// <param name="predicate">An optional predicate that the descendant have to satisfy.</param>
/// <returns></returns>
public static T SafeFindDescendant<T>(this Visual @this, Predicate<T> predicate = null) where T : Visual
{
T result = null;
if (@this == null)
{
return null;
}
// iterate on VisualTree children thanks to VisualTreeHelper
int childrenCount = VisualTreeHelper.GetChildrenCount(@this);
for (int i = 0; i < childrenCount; i++)
{
var currentChild = VisualTreeHelper.GetChild(@this, i);
var typedChild = currentChild as T;
if (typedChild == null)
{
// recursive search
result = ((Visual)currentChild).SafeFindDescendant<T>(predicate);
if (result != null)
{
break;
}
}
else
{
if (predicate == null || predicate(typedChild))
{
result = typedChild;
break;
}
}
}
return result;
}
}
Bunu 50 itibar puanı kazanmak thnink: Burada
Ve
SafeFindDescendant uzatma yöntemidir. Çok zor 50 puan kazandım ..) Niye ödül verene kadar bekledin? =) Cevaplarınız için teşekkürler! – MikroDelÜzgünüm, bunu daha önce görmedim :) Mümkün olduğunca çok WPF sorusunu cevaplamaya çalışıyorum ama hepsine cevap veremiyorum. Ancak her zaman lütuflara bir göz atıyorum :) Eğer sorununuzu çözdüyse Cevap olarak işaretlemeyi unutmayın! – Sisyphe
Sorunuza, içgüdüsel olarak başladı. Bu sizin ödül için 10rep daha az kayıp olacak;) – Sisyphe