2
我有一個TreeView在WPFLINQ查詢 - 在WPF C#一個查詢
工作履行期望的結果我有我使用填充一個TreeView的兩級兩類。
第一個問題是我可以用一個查詢來做到這一點,或者比我在下面做到的更好。
主要問題是我想包括h.ItemId
和ViewDocItems
中的其他列,並仍然在樹視圖中實現層次結構。
現在Title
DocHistory
類是樹的根級別。
和BaseNumber
從BaseHistory
是第二級。
public class DocHistory
{
private ObservableCollection<BaseHistory> mBaseHis = new ObservableCollection<BaseHistory>();
public Guid Id { get; set; }
public Guid ClassId { get; set; }
public string Title { get; set; }
public ObservableCollection<BaseHistory> BaseHis { get { return mBaseline; } }
}
public class BaseHistory
{
public Guid BaseId { get; set; }
public string BaseName { get; set; }
public int BaseNumber { get; set; }
public bool BaseFinal { get; set; }
}
//this guid is only for testing
mGuid = new Guid("0497F3DA-AE3E-40C7-AF91-9B26EEE2A437");
var query = (from d in mContext.Docs
orderby d.Title ascending
join b in mContext.Base on d.DocId equals b.DocId
join h in mContext.ViewDocItems on b.BaseId equals h.BaseId
where h.ItemId == mGuid
select d).Distinct();
List<Database.Doc> DocList = query.ToList();
foreach (Database.Doc result in DocList)
{
DocHistory newHistory = new DocuHistory() { Id = result.DocId, Title = result.Title, ClassId = result.ClassId };
mHistory.Add(newHistory);
var documents = from d in result.Base
orderby d.LineNumber
select new BaseHistory()
{
BaseId = d.BaseId,
Name = d.Title,
BaseFinal = d.Final.Value,
LineNumber = d.LineNumber.Value
};
documents.ToList().ForEach(d => newHistory.BaseHis.Add(d));
}
這裏是我結合
private ObservableCollection<DocHistory> mHistory = new ObservableCollection<DocHistory>();
public ObservableCollection<DocHistory> DocsHistory
{
get
{
return mHistory;
}
}
我使用ItemsSource="{Binding Path=DocsHistory}"
的TreeView的
財產和Hierarchial DataTemplate
被綁定到BaseHis