I’m a C# and a WPF beginner and I’m trying for days to make an Ifc Viewer in my app. I tried many ways to do it but I did not succeed and I turn around.
I got inspired by an other topic on the forum : “How to use Xbim in WPF to visualise an .IFC in 3D”. Currently my xaml file seems like this :
xmlns:presentation="http://schemas.Xbim.com/Presentation"
<Window.Resources>
<ObjectDataProvider x:Key="ModelProvider" IsInitialLoadEnabled="False" />
</Window.Resources>
<Grid Name="MainFrame" DataContext="{StaticResource ModelProvider}">
<presentation:DrawingControl3D x:Name="test3D" Model="{Binding ObjectInstance}"/>
</Grid>
And my C# file :
using System.Windows;
using System.Windows.Data;
using Xbim.Ifc;
using Xbim.ModelGeometry.Scene;
namespace okokokok
{
public partial class MainWindow : Window
{
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:\Users\e.mazzone\Desktop\Mission_C#\Test_Ifc_1.ifc");
var context = new Xbim3DModelContext(model);
context.CreateContext();
ModelProvider.ObjectInstance = model;
}
}
}
This open the Drawing control but we cannot see the IFC. I tried every IFC type but it didn't work. I think there is probably a binding problem between the xaml file and the C# file.
Would anyone be able to advise me or point me towards a good tutorial?
Thanks!
I did create a simple IFC viewer not long ago, my DrawingControl3D is called DrawingControl, and the simplified code looks something like this:
xaml:
cs:
For me it works as expected.