3D未在WPF应用程序中渲染

3D未在WPF应用程序中渲染,wpf,3d,rendering,viewport3d,Wpf,3d,Rendering,Viewport3d,我正在尝试使用下面的代码渲染3D对象。 但是当我运行应用程序时,什么也不显示。它似乎是空白的。我遗漏了什么吗 <Page x:Class="SampleWpfApplication.DemoPage3" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="DemoPage3" xmlns:

我正在尝试使用下面的代码渲染3D对象。 但是当我运行应用程序时,什么也不显示。它似乎是空白的。我遗漏了什么吗

<Page x:Class="SampleWpfApplication.DemoPage3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DemoPage3" xmlns:my="clr-namespace:SampleWpfApplication">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="126*" />
        <RowDefinition Height="126*" />
        <RowDefinition Height="66" />
    </Grid.RowDefinitions>
    <Viewport3D x:Name="theView3D">
        <Viewport3D.Camera>
            <PerspectiveCamera Position="6,6,6" LookDirection="-4,-4,-4"
UpDirection="0,1,0" />
        </Viewport3D.Camera>         
        <ModelVisual3D x:Name="theModel">
            <ModelVisual3D.Content>
                <Model3DGroup>
                    <GeometryModel3D x:Name="theGeometry">
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D Positions="0,1,0 1,-1,1 -1,-1,1 1,-1,-1 -1,-1,-1"
        Normals="0,1,0 -1,0,1 1,0,1 -1,0,-1 1,0,-1"
        TriangleIndices="0,2,1 0,3,1 0,3,4 0,2,4" />
                        </GeometryModel3D.Geometry>
                        <GeometryModel3D.Material>
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <SolidColorBrush Color="Red" Opacity="0.9"/>
                                </DiffuseMaterial.Brush>
                            </DiffuseMaterial>
                        </GeometryModel3D.Material>
                        <GeometryModel3D.BackMaterial>
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <SolidColorBrush Color="Green" Opacity="0.9"/>
                                </DiffuseMaterial.Brush>
                            </DiffuseMaterial>
                        </GeometryModel3D.BackMaterial>
                    </GeometryModel3D>
                </Model3DGroup>
            </ModelVisual3D.Content>
        </ModelVisual3D>
        <ModelVisual3D>
            <ModelVisual3D.Content>
                <Model3DGroup>
                    <DirectionalLight Direction="0,-5,-2" />
                    <DirectionalLight Direction="3,2,2" />
                    <GeometryModel3D x:Name="theGeometry2">
                        <GeometryModel3D.Transform>
                            <ScaleTransform3D ScaleX="2" ScaleY="2" ScaleZ="2"></ScaleTransform3D>
                        </GeometryModel3D.Transform>
                        <GeometryModel3D.Geometry>
                            <MeshGeometry3D Positions="0,1,0 1,-1,1 -1,-1,1 1,-1,-1 -1,-1,-1"
        Normals="0,1,0 -1,0,1 1,0,1 -1,0,-1 1,0,-1"
        TriangleIndices="0,2,1 0,3,1 0,3,4 0,2,4" />
                        </GeometryModel3D.Geometry>
                        <GeometryModel3D.Material>
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <SolidColorBrush Color="#7FB0C4DE" Opacity="0.9"/>
                                </DiffuseMaterial.Brush>
                            </DiffuseMaterial>
                        </GeometryModel3D.Material>
                        <GeometryModel3D.BackMaterial>
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <SolidColorBrush Color="#7FB0C4DE" Opacity="0.9"/>
                                </DiffuseMaterial.Brush>
                            </DiffuseMaterial>
                        </GeometryModel3D.BackMaterial>
                    </GeometryModel3D>
                </Model3DGroup>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>       
</Grid>
</Page>

在中,它似乎对我很好

也许您应该尝试另一台机器或使用Kaxaml,看看是否有任何结果。在这一点上,它可以是任何数量的事情


编辑:我注意到我没有复制
网格.RowDefinitions
。当我添加它们时,它会剪辑视口。如果您删除了这些,它会工作吗?

我尝试在WPF应用程序中渲染Viewport3D,并成功地渲染了它。它显示了一个金字塔网格

从上面的代码中,您会看到一个空白屏幕,因为您没有定义页面的高度和宽度

这是我为您的页面提供的解决方案(请按如下方式添加页面高度和宽度属性):


DesignWidth和DesignHeight仅对设计师有意义。它们甚至不在运行时编译。这有什么帮助?
<Page x:Class="SampleWpfApplication.DemoPage3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d" 
    d:DesignHeight="300" d:DesignWidth="300"
    Title="DemoPage3" xmlns:my="clr-namespace:SampleWpfApplication">