This question is locked. New answers and comments are not allowed.
Hello,
I'm creating a gridview dinamically, I've defined in the App.Resource a DataTemplate as :
In the codebehind of the XAML where I add the column I do :
The UtilityCellTemplateSelector is defined as :
when I pass the var ar .... I got : Reference is not a valid visual DependencyObject.
I need to access to the hyperlinkbutton since I need to specify the parameters to open the detail...
Thanks
Paolo
I'm creating a gridview dinamically, I've defined in the App.Resource a DataTemplate as :
<DataTemplate x:Name="hyperLinkTemplate"><ContentPresenter><HyperlinkButton x:Name="hlClick" Content="{Binding}" Click="hlClick_Click"></HyperlinkButton></ContentPresenter>
</DataTemplate>In the codebehind of the XAML where I add the column I do :
foreach (Colonna colonna in header) { GridViewDataColumn c = new GridViewDataColumn(); c.Header = colonna.N; string columName = string.Format("Colonne[{0}].V", count++); c.DataMemberBinding = new System.Windows.Data.Binding(columName); c.UniqueName = columName; c.DataType = Type.GetType(colonna.T); c.CellTemplateSelector = App.Current.Resources["utilityCellTemplateSelector"] as DataTemplateSelector; if (c.DataType == typeof(DateTime)) { c.DataFormatString = "{0:dd/MM/yyyy}"; c.SortMemberPath = columName; c.SortingState = SortingState.Ascending; } gvContent.Columns.Add(c); }The UtilityCellTemplateSelector is defined as :
public class UtilityCellTemplateSelector : DataTemplateSelector { public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container) { var cell = container as GridViewCell; if (cell != null && cell.DataColumn is GridViewDataColumn) { var column = cell.DataColumn as GridViewDataColumn; string memberPath = column.DataMemberBinding.Path.Path; System.Windows.DataTemplate dataTemplate = App.Current.Resources["hyperLinkTemplate"] as System.Windows.DataTemplate; var ar = dataTemplate.FindChildByType<HyperlinkButton>(); return dataTemplate; } return null; } }when I pass the var ar .... I got : Reference is not a valid visual DependencyObject.
I need to access to the hyperlinkbutton since I need to specify the parameters to open the detail...
Thanks
Paolo