我正在学习如何在WPF应用程序中使用Xbim来创建用户可以旋转和查看的模型的3D视图。我在C#代码中加载我的ifc文件,如下所示:
var model=IfcStore.Open("Images/test.ifc"(
var context=new Xbim3DModelContext(model(
context.CreateContext((
然后,我在XAML中设置了一个视口,如下所示:
<xbim:DrawingControl3D名称=";test3D">lt/xbim:DrawingControl3D>
我正在努力研究如何将两者链接起来,并在视口中显示加载的模型。有人能建议/指出一个好的教程吗?如果我在原地运行应用程序,我可以看到一个空的视口,我可以四处移动,只需要把模型放进去。
谢谢!
感谢您的评论。遗憾的是,这对我不起作用。我不得不移动行ModelProvider.Refresh((;到名为的事件
void MainWindow_Loaded( object sender, RoutedEventArgs e )
{
ModelProvider.Refresh();
}
此外,我在xaml文件中添加了Loaded=";MainWindow_Loaded">
现在,我的两个文件如下:
<Window x:Class="wpf2bim.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:wpf2bim"
xmlns:presentation="http://schemas.Xbim.com/Presentation"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525"
Loaded="MainWindow_Loaded">
<Window.Resources>
<ObjectDataProvider x:Key="ModelProvider" IsInitialLoadEnabled="False" />
</Window.Resources>
<Grid Name="MainFrame" DataContext="{StaticResource ModelProvider}">
<presentation:DrawingControl3D x:Name="test3D" Model="{Binding}" />
</Grid>
和c#文件
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
openFile();
}
void MainWindow_Loaded( object sender, RoutedEventArgs e )
{
ModelProvider.Refresh();
}
private ObjectDataProvider ModelProvider
{
get
{
return MainFrame.DataContext as ObjectDataProvider;
}
}
public void openFile()
{
var model = IfcStore.Open(@"C:SampleHouse.ifc");
var context = new Xbim3DModelContext(model);
context.CreateContext();
ModelProvider.ObjectInstance = model;
}
}
您需要更多的代码。
private ObjectDataProvider ModelProvider
{
get
{
return MainFrame.DataContext as ObjectDataProvider;
}
}
public void openFile()
{
var model = IfcStore.Open("Images/test.ifc");
var context = new Xbim3DModelContext(model);
context.CreateContext();
ModelProvider.ObjectInstance = model;
ModelProvider.Refresh();
}
在xaml方面:
<Window.Resources>
<ObjectDataProvider x:Key="ModelProvider" IsInitialLoadEnabled="False" />
</Window.Resources>
<Grid Name="MainFrame" DataContext="{StaticResource ModelProvider}">
<xbim:DrawingControl3D x:Name="test3D" Model="{Binding}" />
</Grid>