對於那些想要知道的人來說,這是一個自穩定算法的工具。如何綁定ListView以查看一組對象的特定屬性?
說我有幾類,Algorithm
,Rule
,Predicate
,Action
,Graph
,並Node
,如此定義:
using System;
using System.Collections.Generic;
using System.Text;
namespace SMP {
class Algorithm {
public List<Rule> Rules { get; set; }
public Algorithm() {
Rules = new List<Rule>();
}
}
class Rule {
public Predicate Predicate { get; set; }
public Action Action { get; set; }
}
class Predicate {
public string Description { get; set; }
public string Name { get; set; }
public string Expression { get; set; }
}
class Action {
public string Description { get; set; }
public string Name { get; set; }
public string Expression { get; set; }
}
}
我想連接一個兩列ListView
將顯示Predicate.Name
和Action.Name
對於某些Algorithm.Rules
中的每個元素。
注意我用了這個帖子下面的變量名:
ListView algorithm_view;
Algorithm algorithm
我知道我必須設置的algorithm_view
的DataContext
我Algorithm
實例與algorithm_view.DataContext = algorithm
,但我不知道該怎麼在XAML中表示一個像這樣的集合的綁定。
如果它有助於圖片吧,這裏是界面的截圖:
感謝您的回答!我會用'ObservableCollection'而不是'List '嗎? –
在WPF應用程序中,這通常是可取的。 – Sheridan
甜。這需要對我的軟件進行一些重新構建,但是一旦我已經完成所有工作,我會接受你的答案---這似乎是我錯過的關鍵信息,但要做到這一點,我會需要一點時間。謝謝! –