Access controls in the Silverlight DataGrid column header from code

We have custom headers in the Silverlight DataGrid using the ContentTemplate. We have a button in the header and we need to programmatically access the button to connect the event. We use IronPython, so we can not statically bind the event in xaml (plus we use a grid for many different views, so we dynamically generate xaml).

How can we access the controls inside the header of a datagrid column?

+3
source share
2 answers

, , , DataColumnHeader, , .

:

from System.Windows.Media import VisualTreeHelper

def findChildren(parent, findType):
    count = VisualTreeHelper.GetChildrenCount(parent)
    for i in range(count):
        child = VisualTreeHelper.GetChild(parent, i)
        if isinstance(child, findType):
            yield child
        else:
            for entry in findChildren(child, findType):
                yield entry

:

from System.Windows.Controls import Button
from System.Windows.Controls.Primitives import DataGridColumnHeader

for entry in findChildren(self._gridControl, DataGridColumnHeader):
    for button in findChildren(entry, Button):
        button.Click += handler

, grid.Loaded, , .

+2

Source: https://habr.com/ru/post/1737326/


All Articles