0
是否可以將文本框的datacontext設置爲List>的特定索引?textbox Datacontext列表索引
我有我使用圖表的數據上下文的列表,我已經能夠訪問這個框TextChanged與代碼數據:
double d;
if (!double.TryParse(point4.Text, out d))
{
d = 0;
}
ValueList.valueList[3] = new KeyValuePair<string, double>("4th", d);
if (chart1 != null)
{
chart1.Refresh();
}
但如果可能的話,我想只需使用數據上下文。
編輯加我當前類:
public class GraphItems
{
public string Key { get; set; }
public double Data { get; set; }
public GraphItems(string K, double D)
{
Key = K;
Data = D;
}
}
public class GraphData : ObservableCollection<GraphItems>
{
public GraphData()
{
Add(new GraphItems("1st", 0));
Add(new GraphItems("2nd", 4));
Add(new GraphItems("3rd", 3));
Add(new GraphItems("4th", 2));
}
}
好吧,但這裏是另一個問題,我使用的是KeyValuePair,有沒有辦法綁定到KeyValuePair的值? – Herrozerro
@Herrozerro當然,你可以綁定到'Key'和'Value',它們是'KeyValuePair'的屬性。 – McGarnagle
會是什麼樣子?我正在使用{Binding ValueList.valueList [1]}來獲取特定的記錄。 – Herrozerro