0

I have a tree- or menu-like data structure which I want to display in a Panel (specifically a self-made PolarPanel), but all items must be VisualChildren of the same panel.

If I define a HierarchicalDataTemplate, I need to create an ItemsControls and specify it as IsItemsHost, or am I mistaken here? Can I somehow reference the parent's ItemsHost?

    <HierarchicalDataTemplate
        DataType="{x:Type local:ItemsCollection}"
        ItemsSource="{Binding Children}"
        >
        <!--/* "virtual" ItemsHost referencing the parent's ItemsHost? */-->
    </HierarchicalDataTemplate>

(My first workaround was to have a GetAllTheChildren property in the root node which returns all children and all children of the SelectedChild, recursively. This doesn't easily work together with ObservableCollection, because changes have to bubble up to the root to refresh GetAllTheChildren again (which reloads more items than would be neccessary).)

I know I can do it in code-behind by creating and drawing the items' Views into the same parent, but I'm searching for a nice WPF, indirect, automagic way.

EDIT: I am now using an improved workaround, where all ItemControls / Panels are drawn on top of each other. This preserves the hierarchical aspect, which makes this a much better solution than the one mentioned above (with GetAllTheChildren). But it still doesn't answer my question...

This is what it looks like graphically:
PolarMenu example
Note how the hierarchical elements have to be arranged in the same space.

Is there a clean and simple solution to this?

4

1 回答 1

0

我必须承认图形效果非常吸引人,即使我不知道如何使用这种控件!

为了回答您的问题,我从未尝试与主持人共享同一个小组,但我认为这是不可能的。这会破坏视觉树层次结构模式。任何视觉元素只能有一个父元素。

假设每个层级都映射他自己的环,我肯定会用经典的方式来创建这样一个复合 UI。毫无疑问,使用 HierarchicalTemplates 和 ItemsControls 的便利性,即使它可能是一项复杂的任务。

此外,我不明白你的目标是否是某种崩溃,这样一个普通的树视图。在这种情况下,避免使用经典的 WPF 方法将是一场噩梦!

我的解决方案是创建一个自定义面板,能够将他们的孩子安排在一个环上。

那不是全部。它必须同时创建自定义控件和 ItemsControl。第一个将代表必须渲染的环形切片,另一个作为生成器。充当物品持有者的控件将具有两个属性:角度和半径。厚度可以分开。

调用 MeasureOverride 的面板必须考虑环嵌套,并相应地设置其子项的角度和半径。

从我的角度来看,持有控制应该派生自 ContentControl。那是因为您需要渲染切片的形状,而该任务应该由该控件完成。任何特定的嵌入式控件(文本、按钮等)都可以作为内容放置在里面。

当然,这一切都是头脑风暴。我不保证这是最好的解决方案,也不能按原样工作。

希望能帮助到你。

干杯

于 2011-07-26T11:55:48.723 回答