谢谢你所有的评论。可悲的是,这对我不起作用。我不得不移动线 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;
}
}