如何定义数据网格的数据模板?
这可能是一个非常基本的问题,但我对此很陌生,并且依赖于 Google 搜索,所以...
我正在尝试组合一个数据网格,该数据网格显示包含 ID 和多种语言的文本行。我将每一行基于一个类“TextRow”,其中包含 ID 和 LanguageCell 项目的集合,每个项目都包含语言和文本(我计划稍后添加更多):
public class TextRowClass
{
public string Label { get; internal set; }
public Dictionary<string, LanguageCell> TextCells { get; internal set; }
public class LanguageCell
{
public string Language { get; internal set; }
public string Text { get; internal set; }
}
}
我的问题是:如何设置要显示的数据网格LanguageCell 类中的信息如我所愿? (在这种情况下,在单元格中显示文本元素,并使用其他元素(要添加)用于各种其他目的。)我确信它与定义数据模板有关,但我找不到有关它的任何信息。
谢谢!
This is probably a really basic question, but I'm new to this and relying on Google searches, so...
I'm trying to put together a datagrid that displays rows of text containing an ID and multiple languages. I'm basing each row off a class "TextRow" that contains the ID and a collection of LanguageCell items, each containing the language and text (I plan to add more later):
public class TextRowClass
{
public string Label { get; internal set; }
public Dictionary<string, LanguageCell> TextCells { get; internal set; }
public class LanguageCell
{
public string Language { get; internal set; }
public string Text { get; internal set; }
}
}
My question is: How do I set up datagrid to display the information in the LanguageCell class as I want? (In this case, display the Text element in the cell and using other elements (to be added) for various other purposes.) I'm sure it has to do with defining a datatemplate, but I can't find any information about it.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过将类转换为数据表并将其用作我的项目源找到了这个问题的答案。在这样做时,我遇到了数据网格将数据表中的所有内容视为数据行视图的问题,但这篇文章解决了该问题:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/8b2e94b7-3c44-4642-8acc-851de5285062
可能不是最好或最优雅的解决方案,但这是我能找到的唯一一个。
I found the answer to this question in converting the class into a datatable and using that as my itemssource. In doing so, I ran across the problem that datagrids treat everything in the datatable as a datarowview, but this post solved that problem:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/8b2e94b7-3c44-4642-8acc-851de5285062
Likely not the best or most elegant solution, but the only one I was able to find.