代码之家  ›  专栏  ›  技术社区  ›  Michael Rosario

如果您要在Silverlight中构建一个组织结构图生成器,您将使用什么基类来创建图表框?

  •  0
  • Michael Rosario  · 技术社区  · 16 年前

    对于这个问题,让我们假设我们将要展示员工的脸、头衔、部门,以及他们是否喜欢Pi_a Coladas/被雨淋。

    可能看起来像下面这样: http://www.edrawsoft.com/images/examples/Photo-Org-Chart-Full.png

    你能用…

    • system.windows.control.usercontrol?
    • 框架元素?
    • UIONE?
    • 帆布

    为什么?一如既往,谢谢你的建议!非常感谢!

    3 回复  |  直到 16 年前
        1
  •  2
  •   Community Mohan Dere    9 年前

    如果我必须用高级布局创建一个组织结构图控件,我可能会从 Control 并以类似的方式创建“真实”模板化控件,例如 TreeView 控制。这可能是创建新控件的最先进的方法,也是最强大的方法。

    您还可以修改 树视图 ,并使其从中心向下生长,而不是从左上角向下和从左上角向下生长,但很可能难以或不可能将各个级别的布局自定义为 TreeViewItem 不携带任何额外的信息来描述特定节点的布局。

    事实上,我最近做了一些修改 树视图 控制模板,但我偶然发现了一些我不理解的东西。幸运的是,我知道我做错了什么,你可以看到如何改变 树视图 我的中从垂直到水平的子项 question here on Stack Overflow .

        2
  •  0
  •   Paully    16 年前

    我看到过一个使用TreeViewItem和ControlTemplates的网站,但我现在找不到它,我认为它在codeproject上。

    我最近玩的另一个主意是使用2个用户控件、项控件和堆栈面板。

    下面是一个包含文本的组织栏矩形示例,它通过递归地将itemsource设置为其子集合来呈现组织栏控件中的子集合。您可以将根组织栏放在画布上,并使用箭头路径进行播放。我试着指出基础知识,但如果你需要更多,我可以填补空白。

    Public Class OrgBarDataNode  
       Public Property BarColor as New SolidColorBrush(Colors.Red)
       Public Property BarName As String
       Public Property Children as New ObservableCollection(Of OrgBarDataNode)
    End Class
    
    Class MainPage
    ...
       Public Sub Loaded
    
          Dim Root as New OrgBarDataNode With {.BarName = "Root"}
          Dim Child1 as New OrgBarDataNode With {.Barname = "Child1"}
          Root.Children.Add(Child1)
          LayoutRoot.Children.Add(Root)
       End Sub 
    ...
    End Class
    
    <UserControl x:Class="OrgBar">
    <Grid>
        <StackPanel ToolTipService.ToolTip="{Binding BarName}" Cursor="Hand">
            <Rectangle Fill="{Binding BarColor}" Style="{StaticResource RecStyle}"/>
            <TextBlock Text="{Binding BarName}" HorizontalAlignment="Center"               
            Margin="0,10,0,0" />
            <local:OrgGroup Margin="0,20" HorizontalAlignment="Center" 
      DataContext="{Binding Children}" />
        </StackPanel>
        </Grid>
     </UserControl>
    
     <UserControl x:Class="OrgGroup">
      <Grid>
        <!-- this {Binding} to nothing means bind to DataContext}--> 
        <ItemsControl ItemsSource="{Binding}" >
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <local:OrgBar Style="{StaticResource OrgBarStyle}"  
                     DataContext="{Binding}" /> 
                 <!-- this {Binding} refers to the the child node this time}  -->
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
       </Grid>
      </UserControl>
    
        3
  •  0
  •   Eloff    16 年前

    这本质上是一个树结构,就像Paully建议的那样,我将从TreeView(Silverlight工具包)开始,自定义控件模板和TreeView本身。