Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1882 connectés 

  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  CheckBox dans datatemplate WPF

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

CheckBox dans datatemplate WPF

n°2229620
OrcusZ
Pro AMD | .Net lover
Posté le 31-05-2014 à 08:51:31  profilanswer
 

Bonjour à tous,
 
Je vous explique mon problème, j'ai une page dans une page XAML ou une partie du code à un Binding que je récupère d'un web services.
Pas de soucis pour affiché ces informations mais le problème et que je possède une checkbox avec l'id dans un TAG de chaque objet récupérer.
 
Mon problème c'est que je n'arrive pas à récupérer ce tag, j'ai l'erreur "Le nom 'SelectId' n'existe pas dans le contexte actuel".
 
Voici le code XAML :
 

Code :
  1. <ListBox x:Name="listeForm" Height="195" Background="BlanchedAlmond" Margin="0,0,-0.2,0" >
  2.                     <ListBox.ItemTemplate>
  3.                         <DataTemplate >
  4.                             <WrapPanel Orientation="Horizontal">
  5.                                 <CheckBox x:Name="SelectId"
  6.                                 Content="CheckBox"
  7.                                 HorizontalAlignment="Left"
  8.                                 Margin="10,10,0,0"
  9.                                 VerticalAlignment="Top"
  10.                                 Checked="CheckBox_Checked"
  11.                                 Unchecked="CheckBox_Unchecked"
  12.                                     Tag="{Binding Id}"     
  13.                                 />
  14.                                     <TextBlock Text="{Binding id}" Margin="25 5 0 0" Width="20"/>
  15.                                 <TextBlock Text="{Binding nom}" TextWrapping="Wrap" Margin="25 5 0 0" Width="50"/>
  16.                                 <TextBlock Text="{Binding description}" TextWrapping="Wrap" Margin="5 5 0 0" Width="80"/>
  17.                                 <TextBlock Text="{Binding categorie}" TextWrapping="Wrap" Margin="5 5 0 0" Width="75"/>
  18.                                 <TextBlock Text="{Binding prerequi}" TextWrapping="Wrap" Margin="10 5 0 0" Width="70"/>
  19.                                 <TextBlock Text="{Binding prerequi}" TextWrapping="Wrap" Margin="10 5 0 0" Width="75"/>
  20.                                 <TextBlock Text="{Binding date}" TextWrapping="Wrap" Margin="7 5 0 0" Width="65"/>
  21.                                 <TextBlock Text="{Binding heureD}" TextWrapping="Wrap" Margin="6 5 0 0" Width="40"/>
  22.                                 <TextBlock Text="{Binding heureF}" TextWrapping="Wrap" Margin="15 5 0 0" Width="40"/>
  23.                                 <TextBlock Text="{Binding dateL}" TextWrapping="Wrap" Margin="8 5 0 0" Width="85"/>
  24.                                 <TextBlock Text="{Binding prix}" TextWrapping="Wrap" Margin="30 5 0 0" Width="30"/>
  25.                                 <TextBlock Text="{Binding repas}" TextWrapping="Wrap" Margin="15 0 0 0" Width="30"/>
  26.                                 <TextBlock Text="{Binding nbMax}" TextWrapping="Wrap" Margin="45 5 0 0" Width="40"/>
  27.                                 <!--
  28.                                 <TextBlock TextWrapping="Wrap" Margin="50 5 0 0" Width="30">27</TextBlock>-->
  29.                             </WrapPanel>
  30.                         </DataTemplate>
  31.                     </ListBox.ItemTemplate>
  32.                 </ListBox>


 
 
Et j'essaye de récupérer le tag après le click sur un bouton.
 
Merci de votre aide


---------------
Made you your own sentence without believing that of the others...
mood
Publicité
Posté le 31-05-2014 à 08:51:31  profilanswer
 

n°2229623
TheFox37
pourtant chez moi, ça marche
Posté le 31-05-2014 à 11:45:38  profilanswer
 

c'est difficile à dire comme ça, sans le context de ton xaml. à quoi sert cet id dans le tag? le textbox sur lequel l'id est bindé aussi, c'est pour ton debug?


---------------
Mon FeedBack Ebay
n°2229631
OrcusZ
Pro AMD | .Net lover
Posté le 31-05-2014 à 15:43:38  profilanswer
 

Salut,
 
Alors en faite l'id dans le textbox n'est pas indispensable c'est juste de l'affichage basique.
Par contre celui du tag de mon checkbox c'est pour savoir qu'elle box j'ai coché.
 


---------------
Made you your own sentence without believing that of the others...
n°2229632
TheFox37
pourtant chez moi, ça marche
Posté le 31-05-2014 à 16:12:33  profilanswer
 

dans ce cas, pourquoi ne pas avoir une Property IsChecked bindée dans ton VM?


---------------
Mon FeedBack Ebay
n°2229633
OrcusZ
Pro AMD | .Net lover
Posté le 31-05-2014 à 16:19:14  profilanswer
 

Re,
 
La c'est ce que j'ai fait, j'ai mis IsChecked dans ma checkbox, mais je n'arrive qu'a récupérer si la case est coché ou non et pas la valeur qui m'intéresse :/


---------------
Made you your own sentence without believing that of the others...
n°2229634
TheFox37
pourtant chez moi, ça marche
Posté le 31-05-2014 à 16:42:27  profilanswer
 

en gros, dans ton VM, tu dois avoir une liste d'objets.
ces objets ont la fameuse propriété IsChecked, et leur id.
 
ensuite, récupérer la liste des objets qui ont IsChecked à true me semble trivial. La source de ta listbox n'est pas bindée?


---------------
Mon FeedBack Ebay
n°2229635
OrcusZ
Pro AMD | .Net lover
Posté le 31-05-2014 à 16:54:14  profilanswer
 

Re,
 
Ok je fait ça. Par contre je comprend pas ta question, tu entend quoi par source de la listbox?


---------------
Made you your own sentence without believing that of the others...
n°2229636
TheFox37
pourtant chez moi, ça marche
Posté le 31-05-2014 à 16:58:19  profilanswer
 

dans ton xaml : <ListBox x:Name="listeForm" Height="195" Background="BlanchedAlmond" Margin="0,0,-0.2,0" >
 
tu n'as pas un ItemsSource="maListe", c'est fait dans le code behind?


---------------
Mon FeedBack Ebay
n°2229638
OrcusZ
Pro AMD | .Net lover
Posté le 31-05-2014 à 17:06:34  profilanswer
 

Re,
 
Si j'ai listeForm.ItemsSource = formation;
formation étant ma liste de formation  


---------------
Made you your own sentence without believing that of the others...
n°2229640
TheFox37
pourtant chez moi, ça marche
Posté le 31-05-2014 à 17:11:19  profilanswer
 

oui voilà, c'est ce que je disais, c'est fait dans le code behind et pas dans le xaml :)


---------------
Mon FeedBack Ebay
mood
Publicité
Posté le 31-05-2014 à 17:11:19  profilanswer
 

n°2229641
OrcusZ
Pro AMD | .Net lover
Posté le 31-05-2014 à 17:22:35  profilanswer
 

Re,
 
Alors j'avance petit a petit  

Code :
  1. <CheckBox Name="SelectId"
  2.                                 Content="{Binding id}"
  3.                                 HorizontalAlignment="Left"
  4.                                 Margin="10,10,0,0"
  5.                                 VerticalAlignment="Top"
  6.                                 IsChecked="{Binding IsCheckeds, Mode=TwoWay}"


voici mon xaml de ma checkbox
 
Ensuite j'ai un evenement click sur un bouton  

Code :
  1. private void Delete_Click(object sender, RoutedEventArgs e)
  2.         {
  3.             foreach (Formation i in formation)
  4.             {
  5.                 MessageBox.Show(i.IsChecked.ToString());
  6.             }
  7.         }


 
le truc c'est que la case soit coché ou non mon isChecked est toujours faux
 
je précise isChecked fait partie de ma classe formation


---------------
Made you your own sentence without believing that of the others...
n°2229642
TheFox37
pourtant chez moi, ça marche
Posté le 31-05-2014 à 17:25:54  profilanswer
 

{Binding IsCheckeds ...
 
c'est une faute de frappe? sinon voilà pourquoi ça ne fonctionne pas


---------------
Mon FeedBack Ebay
n°2229667
OrcusZ
Pro AMD | .Net lover
Posté le 01-06-2014 à 14:24:16  profilanswer
 

Haha, punaise quoi juste à cause d'une faute de frappe.


---------------
Made you your own sentence without believing that of the others...
n°2229669
TheFox37
pourtant chez moi, ça marche
Posté le 01-06-2014 à 15:46:46  profilanswer
 

ah oui mais dans le binding ça ne pardonne pas :D


---------------
Mon FeedBack Ebay
n°2229670
OrcusZ
Pro AMD | .Net lover
Posté le 01-06-2014 à 17:17:08  profilanswer
 

En tout cas merci, tous fonctionne comme je le veut :D


---------------
Made you your own sentence without believing that of the others...
n°2229692
TheFox37
pourtant chez moi, ça marche
Posté le 02-06-2014 à 09:13:41  profilanswer
 

parfait :sol:


---------------
Mon FeedBack Ebay

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  CheckBox dans datatemplate WPF

 

Sujets relatifs
checkbox dont les case à cocher sont remplis par des champs d'une tablBoucle sur userform et checkbox
Comment importer ColorDialog (windows.forms) dans WPF en VB.NET ?Sauvegarder choix checkbox
Attribut readonly pas actif pour un input type checkboxPetit soucis avec code checkbox sur VB
Résultat de checkbox dans une cellule. Excel 2007Validation de checkbox sous visual basic 2008
Insertion checkbox dans page html et affichage valeur[MVVM/WPF] Binding et DependencyProperty avec une ObservableCollection
Plus de sujets relatifs à : CheckBox dans datatemplate WPF


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)