I'm trying to build a SharpGL app with WPF, but have trouble integrating a view model.
I bind the DataContext of an OpenGLControl to an OpenGLControl property in my ViewModel and create events for the drawing functions in the view model, but they never get called.
The OpenGLControl just appears as a black screen. When I just implement the drawing function in a code behind xaml.cs file it works, but I really want to use a viewModel.
<Window.DataContext>
<local:ViewModel />
</Window.DataContext>
[...]
<StackPanel Orientation="Horizontal">
<GroupBox Width="80" Header="Controls">
<StackPanel>
<TextBox Text="{Binding TranslationX}" />
<TextBox Text="{Binding TranslationY}" />
<TextBox Text="{Binding TranslationZ}" />
</StackPanel>
</GroupBox>
<sharpGL:OpenGLControl x:Name="GLControl" DataContext="{Binding OpenGLControl}" MinWidth="350"/>
</StackPanel>
ViewModel code:
private OpenGLControl openGLControl = new OpenGLControl();
public OpenGLControl OpenGLControl
{
get
{
return openGLControl;
}
set
{
openGLControl = value;
NotifyPropertyChanged(); //Custom implementation of
//INotifyPropertyChanged
}
}
public ViewModel()
{
OpenGLControl.OpenGLDraw += drawEvent;
}
private void drawEvent(object sender, OpenGLEventArgs args)
{
draw(args.OpenGL); // draws a number of vertices, works when used in
// code behind
}