ItemsControl
テンプレートを使用してデータをバインドするもの があります。
<ItemsControl ItemsSource="{Binding MyCollection}" x:Name="MyCollectionControl" ItemTemplate="{DynamicResource MyCollectionTemplate}" />
MyCollectionはのタイプでNameValueCollection
あり、次のバインディングは機能しません。正しい数のペアを入力TextBlock
していますが、制限された値を取得していません。
レンプレート
<DataTemplate x:Key="MyCollectionTemplate">
<Grid>
<TextBlock Text="{Binding Path=Value, Mode=OneWay}"/>
<TextBox Name="CValue"/>
</Grid>
</DataTemplate>
mainWindow
string[] dataCollection=new string[5];
....
....
Student studentObject=new Student("1",dataCollection);
this.dataContext = studentObject;
学生クラス
public class Student
{
public string Id;
public NameValueCollection MyCollection {get; set;}
public Student(string id, params string[] additionalInfo)
{
Id = id;
if (additionalInfo != null)
{
MyCollection=new NameValueCollection();
foreach (string s in MyCollection)
{
string[] tokens = s.Split('|');
if (tokens.Length == 2)
MyCollection.Add(tokens[0], tokens[1]);
}
}
}
}
バインドするときに私がしている間違っていることは何ですかNameValueCollection
。
アドバイスしてください。