我想显示2个多维数据集,只需点击一下按钮。首先,第一个多维数据集会在删除后显示,并在C#中的WPF应用程序中显示另一个多维数据集,所有操作都应该只需点击一下按钮就可以了?
答案 0 :(得分:1)
试试那个PLZ
<Grid>
<Button Content="Draw cube" Margin="167,260,161,0" Click="Button_Click"></Button>
<Viewport3D Name="viewport3D1" Visibility="Hidden">
<Viewport3D.Camera>
<PerspectiveCamera x:Name="camMain" Position="6 5 6" LookDirection="-6 -5 -4">
</PerspectiveCamera>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight x:Name="dirLightMain" Direction="-1,-1,-1">
</DirectionalLight>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D x:Name="meshMain"
Positions="0 0 0 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 1"
TriangleIndices="2 3 1 2 1 0 7 1 3 7 5 1 6 5 7 6 4 5 6 2 0 2 0 4 2 7 3 2 6 7 0 1 5 0 5 4">
</MeshGeometry3D>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial x:Name="matDiffuseMain">
<DiffuseMaterial.Brush>
<SolidColorBrush Color="Red"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
<Viewport3D Name="viewport3D2" Visibility="Hidden">
<Viewport3D.Camera>
<PerspectiveCamera x:Name="camMain2" Position="8 5 4" LookDirection="-6 -5 -4">
</PerspectiveCamera>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight x:Name="dirLightMain2" Direction="-1,-1,-1">
</DirectionalLight>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D x:Name="meshMain2"
Positions="0 0 0 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 1"
TriangleIndices="2 3 1 2 1 0 7 1 3 7 5 1 6 5 7 6 4 5 6 2 0 2 0 4 2 7 3 2 6 7 0 1 5 0 5 4">
</MeshGeometry3D>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial x:Name="matDiffuseMain2">
<DiffuseMaterial.Brush>
<SolidColorBrush Color="Blue"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Grid>
您只需在按钮事件中使用计时器即可更改多维数据集的可见性
private Timer _timer;
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
viewport3D1.Visibility = Visibility.Visible;
_timer = new Timer(1000); // Set up the timer for 1 seconds
_timer.Elapsed+=new ElapsedEventHandler(_timer_Elapsed);
_timer.Enabled = true; // Enable it
}
public void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
Dispatcher.Invoke(new Action(() =>
{
viewport3D1.Visibility = Visibility.Hidden;
viewport3D2.Visibility = Visibility.Visible;
}));
}