계층 적 컬렉션 모델을 만들기 위해 내 개체를 수정하려고합니다. 도움이 필요해. 내 객체는 좋은 및 GoodCategory 있습니다WPF TreeView의 컬렉션을 사용하도록 수업을 수정하는 방법
public class Good
{
int _ID;
int _GoodCategory;
string _GoodtName;
public int ID
{
get { return _ID; }
}
public int GoodCategory
{
get { return _GoodCategory; }
set
{
_GoodCategory = value;
}
}
public string GoodName
{
get { return _GoodName; }
set
{
_GoodName = value;
}
}
public Good(IDataRecord record)
{
_ID = (int)record["ID"];
_GoodtCategory = (int)record["GoodCategory"];
}
}
public class GoodCategory
{
int _ID;
string _CategoryName;
public int ID
{
get { return _ID; }
}
public string CategoryName
{
get { return _CategoryName; }
set
{
_CategoryName = value;
}
}
public GoodCategory(IDataRecord record)
{
_ID = (int)record["ID"];
_CategoryName = (string)record["CategoryName"];
}
}
그리고 나는이 두 개체 컬렉션이 있습니다
public class GoodsList : ObservableCollection<Good>
{
public GoodsList()
{
string goodQuery = @"SELECT `ID`, `ProductCategory`, `ProductName`, `ProductFullName` FROM `products`;";
using (MySqlConnection conn = ConnectToDatabase.OpenDatabase())
{
if (conn != null)
{
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = productQuery;
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Add(new Good(rdr));
}
}
}
}
}
public class GoodCategoryList : ObservableCollection<GoodCategory>
{
public GoodCategoryList()
{
string goodQuery = @"SELECT `ID`, `CategoryName` FROM `product_categoryes`;";
using (MySqlConnection conn = ConnectToDatabase.OpenDatabase())
{
if (conn != null)
{
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = productQuery;
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Add(new GoodCategory(rdr));
}
}
}
}
}
그래서 나는 데이터베이스에서 데이터를 가져와 두 개의 컬렉션을 가지고 있습니다. 하지만 WPF TreeView에서 HierarchicalDataTemplate과 함께 thats 컬렉션을 사용하고 싶습니다. 나는 Hierarlichal Objects의 예와 함께 많은 포스트를 보았지만 스틸은 내 오브젝트를 계층 적으로 만드는 법을 모릅니다. 도와주세요.