1

我想知道是否有人知道在 XAML 中是否有可能有一个 ListBox,其 DataTemplate 将 ListBoxItem 定义为 3d 元素。类似于以下内容:

                <ListBox x:Name="lst3D" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Viewport3D>
                            <Viewport2DVisual3D>
                                <Viewport2DVisual3D.Transform>
                                    <RotateTransform3D>
                                        <RotateTransform3D.Rotation>
                                            <AxisAngleRotation3D Angle="40" Axis="0, 1, 0" />
                                        </RotateTransform3D.Rotation>
                                    </RotateTransform3D>
                                </Viewport2DVisual3D.Transform>
                                <Viewport2DVisual3D.Geometry>
                                    <MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"
                        TextureCoordinates="0,0 0,1 1,1 1,0" 
                        TriangleIndices="0 1 2 0 2 3"/>
                                </Viewport2DVisual3D.Geometry>
                                <Viewport2DVisual3D.Material>
                                    <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="AliceBlue"/>
                                </Viewport2DVisual3D.Material>

                                <Label>Hello, 3D</Label> // we'd like to databind controls like this one

                            </Viewport2DVisual3D>
                        </Viewport3D>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBoxItem />
                <ListBoxItem />
                <ListBoxItem />
            </ListBox>

有人看过这种事情吗/有什么建议吗?

非常感谢,bv

4

2 回答 2

0

有几种方法可以做到这一点。

您可以将 DataTemplate 更改为 ControlTemplate,并将其应用于 ListBox 中的所有项目。但是您不能将其绑定到特定的数据类型。

另一个选项是将 DataTemplate 移动到资源部分,并将 DataType 设置为您希望显示的项目的类型。然后您可以使用绑定来绑定到项目的属性等。

于 2009-03-26T22:33:52.547 回答
0

将按钮替换为内容控件,例如,

  <ContentControl Content="{Binding}" />
它看起来Viewpord3D也不需要布局空间,所以我需要将它包装在 a<Grid Height="100" Width="100">...</Grid>中以查看任何内容。

于 2009-03-27T06:30:44.663 回答