Bonjour,
Je voudrais créer des datatemplate en code (je suis en vb.net).
J'ai une liste de nom que je boucle dessus et pour chaque nom je veux créer un datatemplate avec un grid et dans ce grid mettre 3 colonnes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
For y As Integer = 0 To listePersonnes.Count - 1
Dim gridGrille As FrameworkElementFactory = New FrameworkElementFactory(GetType(Grid))
Dim firstColumn As FrameworkElementFactory = New FrameworkElementFactory(GetType(ColumnDefinition))
Dim unLabel As FrameworkElementFactory = New FrameworkElementFactory(GetType(Label))
unLabel.SetValue(Label.ContentProperty, listePersonnes(y).Nom)
firstColumn.AppendChild(unLabel)
Dim secondColumn As FrameworkElementFactory = New FrameworkElementFactory(GetType(ColumnDefinition))
Dim listeEmi As FrameworkElementFactory = New FrameworkElementFactory(GetType(List))
Dim thirdColumn As FrameworkElementFactory = New FrameworkElementFactory(GetType(ColumnDefinition))
Dim listeAvis As FrameworkElementFactory = New FrameworkElementFactory(GetType(List))
thirdColumn.AppendChild(listeAvis)
gridGrille.AppendChild(firstColumn)
gridGrille.AppendChild(secondColumn)
gridGrille.AppendChild(thirdColumn)
Dim dataGridColonn As DataGridColumn = DataGridChaineGroupe1.Columns(y)
Dim unTemplateColumn As DataGridTemplateColumn = DataGridChaineGroupe1.Columns(y + 1)
unTemplateColumn.CellTemplate = New DataTemplate
unTemplateColumn.CellTemplate.VisualTree = gridGrille
Next |
Déja la ça plante:
Le type 'ColumnDefinition' doit implémenter IAddChild pour être utilisé dans AppendChild de FrameworkElementFactory
Donc j'ai crée une classe qui implémente IAddChild :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
Imports System.Windows.Markup
Public Class ColumnTemplate
Inherits ColumnDefinition
Implements IAddChild
Public Sub AddChild(value As Object) Implements System.Windows.Markup.IAddChild.AddChild
CType(Me, IAddChild).AddChild(value)
End Sub
Public Sub AddText(text As String) Implements System.Windows.Markup.IAddChild.AddText
End Sub
End Class |
Et la j'ai ce message d'erreur:
1 2
|
{Impossible d'évaluer l'expression, car le thread actuel se trouve dans un état de dépassement de capacité de la pile.} |
Merci d'avance
Partager