Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess to DataTemplate Control of WPF Toolkit DataGridCell at Runtime, How?
    text
    copied!<p>I have a DataGrid defined with WPF Toolkit. The CellEditingTemplate of this DataGrid is associated at runtime with a custom function that build a FrameworkElementFactory element.</p> <p>Now I have to access to control that is inserted inside DataTemplate of CellEditingTempleta, but I do not know how to do.</p> <p>On web I found a useful ListView Helper...</p> <pre><code>public static class ListViewHelper { public static FrameworkElement GetElementFromCellTemplate(ListView listView, Int32 column, Int32 row, String name) { if (row &gt;= listView.Items.Count || row &lt; 0) { throw new ArgumentOutOfRangeException("row"); } GridView gridView = listView.View as GridView; if (gridView == null) { return null; } if (column &gt;= gridView.Columns.Count || column &lt; 0) { throw new ArgumentOutOfRangeException("column"); } ListViewItem item = listView.ItemContainerGenerator.ContainerFromItem(listView.Items[row]) as ListViewItem; if (item != null) { GridViewRowPresenter rowPresenter = GetFrameworkElementByName&lt;GridViewRowPresenter&gt;(item); if (rowPresenter != null) { ContentPresenter templatedParent = VisualTreeHelper.GetChild(rowPresenter, column) as ContentPresenter; DataTemplate dataTemplate = gridView.Columns[column].CellTemplate; if (dataTemplate != null &amp;&amp; templatedParent != null) { return dataTemplate.FindName(name, templatedParent) as FrameworkElement; } } } return null; } private static T GetFrameworkElementByName&lt;T&gt;(FrameworkElement referenceElement) where T : FrameworkElement { FrameworkElement child = null; for (Int32 i = 0; i &lt; VisualTreeHelper.GetChildrenCount(referenceElement); i++) { child = VisualTreeHelper.GetChild(referenceElement, i) as FrameworkElement; System.Diagnostics.Debug.WriteLine(child); if (child != null &amp;&amp; child.GetType() == typeof(T)) { break; } else if (child != null) { child = GetFrameworkElementByName&lt;T&gt;(child); if (child != null &amp;&amp; child.GetType() == typeof(T)) { break; } } } return child as T; } } </code></pre> <p>this code work with the ListView object but not with the DataGrid object.</p> <p>How can use something like this in DataGrid?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload