jayhf / OpenTkControl

A faster way to use OpenTk in WPF without Forms dependencies
MIT License
30 stars 6 forks source link

impossible add to designer (VS c# WPF) #6

Open Titibo26 opened 5 years ago

Titibo26 commented 5 years ago

Hey,

When i try to add both UIOpenTKControl or threading one into the designer of my C# apps, it gives me an error :

"ArgumentNullException : Value can't be null. Parameter name : window"

I think it's making some trouble on my XAML code. Tried to fixe it but i didn't find the solution. I tried to reinstal everything. Same error occurs with the example solution. BackTrace is :

à System.Windows.Interop.WindowInteropHelper..ctor(Window window) à OpenTkControl.OpenTkControlBase.OnLoaded(Object sender, RoutedEventArgs args) à OpenTkControl.UiOpenTkControl.OnLoaded(Object sender, RoutedEventArgs args) à OpenTkControl.OpenTkControlBase.<.ctor>b__49_5(Object sender, RoutedEventArgs args) à System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) à System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) à System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) à System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) à System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent) à System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root) à MS.Internal.LoadedOrUnloadedOperation.DoWork() à System.Windows.Media.MediaContext.FireLoadedPendingCallbacks() à System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() à System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) à System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) à System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Thank you very much,

jayhf commented 5 years ago

What is the XAML code you tried to add it with? Did you take a look at the example code?

Titibo26 commented 5 years ago

Hi,

Ofc i tried the example code but i got the same error. Today i tried it on an other computer so i believe it's in the code or i'm doing something wrong :(.

Here is the XAML code added automatically :

<Window x:Class="OpenTkControlExample.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:openTkControl="clr-namespace:OpenTkControl;assembly=OpenTkControl"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <openTkControl:ThreadOpenTkControl x:Name="OpenTkControl" GlRender="OpenTkControl_OnGlRender" ExceptionOccurred="OpenTkControl_OnExceptionOccurred"/>
    </Grid>
</Window>

error_opentkcontrol

jayhf commented 5 years ago

The control can't render properly within the designer view, but it should work fine when you actually run the code. The easiest solution to this issue is disabling project code in the designer. See this for more information: https://docs.microsoft.com/en-us/visualstudio/designers/debugging-or-disabling-project-code-in-xaml-designer?view=vs-2017 Alternatively, you can modify the code to add checks to see if its running in the designer and disable anything that calls a function that won't work properly.

rickberkers commented 3 years ago

Could this merged fix be updated on NuGet?

jayhf commented 3 years ago

@rickberkers Yes, I'll try to get the other PR merged and then put this on NuGet sometime this weekend.