OpenTkControl icon indicating copy to clipboard operation
OpenTkControl copied to clipboard

impossible add to designer (VS c# WPF)

Open Titibo26 opened this issue 7 years ago • 5 comments

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,

Titibo26 avatar Jan 18 '19 15:01 Titibo26

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

jayhf avatar Jan 18 '19 19:01 jayhf

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

Titibo26 avatar Jan 19 '19 11:01 Titibo26

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.

jayhf avatar Jan 28 '19 18:01 jayhf

Could this merged fix be updated on NuGet?

rickberkers avatar Sep 24 '20 22:09 rickberkers

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

jayhf avatar Sep 24 '20 23:09 jayhf