salut,

je viens d'integrer le mode du WPF,et j'aurai besoin d'aide.

j'essaye de creer des controls et de faire un binding dynamique sur une proprieté de ma viewmodel.cs

mon code c#
Code C# : 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
public partial class UserControl1 : UserControl
          {
              public UserControl1()
	  {
	    InitializeComponent();
	    this.DataContext = new MyViewModel();
	    this.Loaded += new RoutedEventHandle(UserControl_Loaded);
	   }
 
	private void UserControl_Loaded(object sender, RoutedEventArgs e)
		{
	                 List<Sport> sports = REcupSport();
                              foreach (Sport spo in sports)
                               {
		  LayoutRoot.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
		  TextBox textblockid = new TextBox();
		  textblockid.SetValue(TextBox.MarginProperty, new Thickness(10));
		  textblockid.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
		  Binding myBinding = new Binding("MyDataProperty");
		  myBinding.Source = this.DataContext;
		  textblockid.SetBinding(TextBlock.TextProperty, myBinding);
	               LayoutRoot.Children.Add(textblockid);
 
 
		}
lorsque j'essaye ce code les controls sont crees mais pas de binding????

mais lorsque j'essaye uu binding sur Xaml ça marche

Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
Text="{Binding Path=MyDataProperty, Mode=TwoWay}"
des idées