आपको बस अपने डेटाग्रिड के DataGridColumnHeadersPresenter को पुनर्प्राप्त करना होगा और इसके कॉन्टेक्स्टमेनू को सेट करना होगा।
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;
}
}
मैं आप इस 50 प्रतिष्ठा अंक जीतने thnink:
और यहाँ SafeFindDescendant विस्तार विधि है। मेरी इतनी कड़ी मेहनत से 50 अंक अर्जित हुए ..) आपने तब तक इंतजार क्यों किया जब तक मैं इसे बक्षीस के साथ पोस्ट नहीं करता? =) आपके लिए Thx जवाब!) – MikroDel
क्षमा करें मैंने इसे जल्द से जल्द नहीं देखा :) मैं जितना संभव हो उतना WPF प्रश्नों का उत्तर देने का प्रयास करता हूं, लेकिन सभी का जवाब नहीं दे सकता। हालांकि मैं हमेशा बक्षीस पर एक नज़र डालता हूं :) अगर आपकी समस्या हल हो जाती है तो जवाब के रूप में चिह्नित करना न भूलें! – Sisyphe
आपके प्रश्न को ऊपर उठाया क्योंकि यह interresting था। यह आपके बक्षीस के लिए 10rep कम खो जाएगा;) – Sisyphe