Bonjour,
je crée un User control tout bête .

XAML:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
<Grid x:Name="LayoutRoot">
		<TextBlock x:Name="TDate" Text="Date :"/>
		<TextBlock x:Name="TTitle" Text="Title :"/>
		<TextBlock x:Name="TComment" Text="Commentaire :"/>
		<TextBlock x:Name="TDateItem" />
		<TextBlock x:Name="TTitleItem" />
		<TextBlock x:Name="TCommentItem" />
	</Grid>
.CS:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
public partial class MyControl : UserControl
	{
		public string Date
		{
			get
			{
				return this.TDateItem.Text;
			}
			set
			{
				this.TDateItem.Text = value;
			}
		}
 
		public string Title
		{
			get
			{
				return this.TTitleItem.Text;
			}
			set
			{
				this.TTitleItem.Text = value;
			}
		}
 
		public string Commentaire
		{
			get
			{
				return this.TCommentItem.Text;
			}
			set
			{
				this.TCommentItem.Text = value;
			}
		}
 
		public MyControl()
		{
			// Required to initialize variables
			InitializeComponent();
		}
	}

dans ma page j'ai une ListBox,

XAML:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
<ListBox x:Name="MyListBox" Style="{StaticResource ListBoxStyle1}" ItemContainerStyle="{StaticResource ListBoxItemStyle1}">
			<ListBoxItem Height="85" Style="{StaticResource ListBoxItemStyle1}" Content="ListBoxItem"/>
		</ListBox>
dans le CS:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
for (int i = 0; i < 12; i++)
{
       this. MyListBox.Items.Add(i.ToString());
}
ça marche très bien.

si je fais:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
for (int i = 0; i < 1; i++)
{
       MyControl Ctrl = new I MyControl();
       Ctrl.Date = "01/01/0" + i.ToString();
       Ctrl.Title = "Title" + i.ToString();
       Ctrl.Commentaire = "Com" + i.ToString();
       this. MyListBox.Items.Add(Ctrl);				
}
ça marche aussi.

mais si je lui ajoute plus d'un item:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
for (int i = 0; i < 2; i++)
{
       MyControl Ctrl = new I MyControl();
       Ctrl.Date = "01/01/0" + i.ToString();
       Ctrl.Title = "Title" + i.ToString();
       Ctrl.Commentaire = "Com" + i.ToString();
       this. MyListBox.Items.Add(Ctrl);				
}
j'ai un message d'erreur:
La valeur n'est pas comprise dans la plage attendue.

je ne comprends pas pourquoi cela ne marche pas cela marché en 2beta1.

Quelqu'un a t il une idée ?

merci d'avance.

ALCINA