【问题标题】:Can you tell me some ways for this model in UI WPF?你能告诉我这个模型在 UI WPF 中的一些方法吗?
【发布时间】:2011-08-17 01:40:16
【问题描述】:

我正在做这个设计:

How can I model this class in a database?

但我在 WPF 中这样做。我对如何创建一个界面 WPF 来添加目标有点困惑。我的意思是,只有接口(程序设计)来建模链接问题。

结果:

<TreeView Name="treeView1">
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate DataType="{x:Type data:Objective}" ItemsSource="{Binding Path=Objectives}" >
            <TextBlock Text="{Binding Name}" />
        </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>

【问题讨论】:

  • 你是说外键问题?
  • 不完全是。我的意思是,我将在程序中创建类别和子类别。我打算处理数据网格控件和几个dataGridDetails。我想听听一些想法来在 WPF 中做一个好的界面或 UI 设计。我说清楚了吗?
  • 也许其他人认为使用 treeView 更好
  • 带有自定义ItemContainerStyleTreeView 控件很可能是最简单的解决方案。但是,如果您希望能够内联编辑数据,您也可以尝试实现 TreeListView 类似的控件。

标签: c# wpf database datagrid


【解决方案1】:

您可以将 TreeView 与 HierarchicalDataTemplate 一起使用,如下所示(取自 Here):

 public class WebPage
{
    public string Href { get; set; }
    public string PageTitle { get; set; }
    public List<WebPage> LinksInPage { get; set; }
}

public class Root
{
    public string Title { get; set; }
    public string Url { get; set; }
    public List<WebPage> WebPages { get; set; }
}


    <HierarchicalDataTemplate DataType="{x:Type data:Root}"
                              ItemsSource="{Binding Path=WebPages}">
                <TextBlock Text="{Binding Title}"></TextBlock>
    </HierarchicalDataTemplate>

    <HierarchicalDataTemplate DataType="{x:Type data:WebPage}"
                              ItemsSource="{Binding Path=LinksInPage}">
                <TextBlock Text="{Binding PageTitle}"></TextBlock>
    </HierarchicalDataTemplate>

【讨论】:

  • 非常感谢,这个例子对我有帮助
  • 请检查这个问题:stackoverflow.com/questions/7082488/…
  • 我该如何提供帮助 - 有几个答案,这似乎是正确的方向。您是否正在寻找直接从 XAML 设置排名字符串的方法?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多