<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Prevent user control to be rendered in design mode. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/prevent-user-control-to-be-rendered-in-design-mode/m-p/11752010#M9990</link>
    <description>&lt;P&gt;I guess it is more about programming question.&amp;nbsp; So I am creating a user control to display the block without opening it in AutoCAD.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The user control using WindowsFormHost. And that windows form control uses an AutoCAD .NET API to display the drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that the AutoCAD .NET dll is only available to call when AutoCAD is running. And every time I open the User control in XAML designer, it throws an error because the Win form control won't load the AutoCAD .DLL.&lt;/P&gt;&lt;P&gt;The code is quite long, so I take some snaps of it, so hopefully, it is enough.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The WPF UserControl holds a WinForm Control.&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&amp;lt;DockPanel&amp;gt;
    &amp;lt;StackPanel  DockPanel.Dock=&lt;SPAN class=""&gt;"Right"&lt;/SPAN&gt; Orientation=&lt;SPAN class=""&gt;"Vertical"&lt;/SPAN&gt;&amp;gt;
        &amp;lt;telerik:RadButton Name=&lt;SPAN class=""&gt;"ZoomOutBtn"&lt;/SPAN&gt;  Click=&lt;SPAN class=""&gt;"ZoomOutBtn_OnClick"&lt;/SPAN&gt;&amp;gt;Zoom Out&amp;lt;/telerik:RadButton&amp;gt;
        &amp;lt;telerik:RadButton Name=&lt;SPAN class=""&gt;"ZoomInBtn"&lt;/SPAN&gt;  Click=&lt;SPAN class=""&gt;"ZoomInBtn_OnClick"&lt;/SPAN&gt;&amp;gt;Zoom In&amp;lt;/telerik:RadButton&amp;gt;
        &amp;lt;telerik:RadButton Name=&lt;SPAN class=""&gt;"RefreshBtn"&lt;/SPAN&gt; Click=&lt;SPAN class=""&gt;"RefreshBtn_OnClick"&lt;/SPAN&gt;&amp;gt;Refresh&amp;lt;/telerik:RadButton&amp;gt;
    &amp;lt;/StackPanel&amp;gt;

    &amp;lt;Grid DockPanel.Dock=&lt;SPAN class=""&gt;"Bottom"&lt;/SPAN&gt;&amp;gt;
        &amp;lt;TextBlock Name=&lt;SPAN class=""&gt;"FilePathTb"&lt;/SPAN&gt; Text=&lt;SPAN class=""&gt;"{Binding TargetFilePath}"&lt;/SPAN&gt;&amp;gt;&amp;lt;/TextBlock&amp;gt;
    &amp;lt;/Grid&amp;gt;

    &amp;lt;WindowsFormsHost MinWidth=&lt;SPAN class=""&gt;"500"&lt;/SPAN&gt; MinHeight=&lt;SPAN class=""&gt;"400"&lt;/SPAN&gt; &amp;gt;
        &amp;lt;Gui:GsPreviewCtrl x:Name=&lt;SPAN class=""&gt;"GsPreviewCtrl"&lt;/SPAN&gt;/&amp;gt;
    &amp;lt;/WindowsFormsHost&amp;gt;

&amp;lt;/DockPanel&amp;gt;&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;Win Form Control itself.&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;GsPreviewCtrl&lt;/SPAN&gt; : &lt;SPAN class=""&gt;Control&lt;/SPAN&gt;
{
    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;region&lt;/SPAN&gt; Fields&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;// current dwg&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; Database mCurrentDwg;

    &lt;SPAN class=""&gt;// Gs specific&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; Manager MpManager;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; Device  mpDevice;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; Model   mpModel;

    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; View mpView;

    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;static&lt;/SPAN&gt; &lt;SPAN class=""&gt;bool&lt;/SPAN&gt; IsDesignMode =&amp;gt; UserControls.Utils.IsDesignMode(&lt;SPAN class=""&gt;null&lt;/SPAN&gt;);

    &lt;SPAN class=""&gt;// A list of other properties and methods to render the object on the device.&lt;/SPAN&gt;
    .....
}&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;A helper method to tell if the Winform control is in design mode or not.&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;static&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;Utils&lt;/SPAN&gt;
{
    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;region&lt;/SPAN&gt; Static Fields&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;endregion&lt;/SPAN&gt;&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;region&lt;/SPAN&gt; Static Properties&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;static&lt;/SPAN&gt; &lt;SPAN class=""&gt;bool&lt;/SPAN&gt; DesignMode { &lt;SPAN class=""&gt;get&lt;/SPAN&gt;; } = &lt;SPAN class=""&gt;string&lt;/SPAN&gt;.Equals(
        Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule?.FileName),
        &lt;SPAN class=""&gt;"devenv"&lt;/SPAN&gt;,
        StringComparison.OrdinalIgnoreCase
    );

    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;endregion&lt;/SPAN&gt;&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;region&lt;/SPAN&gt; Static Methods&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;static&lt;/SPAN&gt; &lt;SPAN class=""&gt;bool&lt;/SPAN&gt; &lt;SPAN class=""&gt;IsDesignMode&lt;/SPAN&gt;(&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;this&lt;/SPAN&gt; Control control&lt;/SPAN&gt;)&lt;/SPAN&gt; { &lt;SPAN class=""&gt;return&lt;/SPAN&gt; DesignMode; }

    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;endregion&lt;/SPAN&gt;&lt;/SPAN&gt;
}&lt;/PRE&gt;&lt;P&gt;However, the helper method doesn't tell if the object is in design mode or not. This piece of code comes from the original post from AutoDesk Dev Blog.&lt;/P&gt;&lt;P&gt;&lt;A href="https://adndevblog.typepad.com/autocad/2014/12/drawing-preview-in-wpf-palette.html" target="_blank" rel="nofollow noopener noreferrer"&gt;https://adndevblog.typepad.com/autocad/2014/12/drawing-preview-in-wpf-palette.html&lt;/A&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;The error itself:&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://i.stack.imgur.com/Uy0Zu.png" border="0" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2023 21:30:24 GMT</pubDate>
    <dc:creator>gary.wuEQ8E4</dc:creator>
    <dc:date>2023-02-13T21:30:24Z</dc:date>
    <item>
      <title>Prevent user control to be rendered in design mode.</title>
      <link>https://forums.autodesk.com/t5/net-forum/prevent-user-control-to-be-rendered-in-design-mode/m-p/11752010#M9990</link>
      <description>&lt;P&gt;I guess it is more about programming question.&amp;nbsp; So I am creating a user control to display the block without opening it in AutoCAD.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The user control using WindowsFormHost. And that windows form control uses an AutoCAD .NET API to display the drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that the AutoCAD .NET dll is only available to call when AutoCAD is running. And every time I open the User control in XAML designer, it throws an error because the Win form control won't load the AutoCAD .DLL.&lt;/P&gt;&lt;P&gt;The code is quite long, so I take some snaps of it, so hopefully, it is enough.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The WPF UserControl holds a WinForm Control.&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&amp;lt;DockPanel&amp;gt;
    &amp;lt;StackPanel  DockPanel.Dock=&lt;SPAN class=""&gt;"Right"&lt;/SPAN&gt; Orientation=&lt;SPAN class=""&gt;"Vertical"&lt;/SPAN&gt;&amp;gt;
        &amp;lt;telerik:RadButton Name=&lt;SPAN class=""&gt;"ZoomOutBtn"&lt;/SPAN&gt;  Click=&lt;SPAN class=""&gt;"ZoomOutBtn_OnClick"&lt;/SPAN&gt;&amp;gt;Zoom Out&amp;lt;/telerik:RadButton&amp;gt;
        &amp;lt;telerik:RadButton Name=&lt;SPAN class=""&gt;"ZoomInBtn"&lt;/SPAN&gt;  Click=&lt;SPAN class=""&gt;"ZoomInBtn_OnClick"&lt;/SPAN&gt;&amp;gt;Zoom In&amp;lt;/telerik:RadButton&amp;gt;
        &amp;lt;telerik:RadButton Name=&lt;SPAN class=""&gt;"RefreshBtn"&lt;/SPAN&gt; Click=&lt;SPAN class=""&gt;"RefreshBtn_OnClick"&lt;/SPAN&gt;&amp;gt;Refresh&amp;lt;/telerik:RadButton&amp;gt;
    &amp;lt;/StackPanel&amp;gt;

    &amp;lt;Grid DockPanel.Dock=&lt;SPAN class=""&gt;"Bottom"&lt;/SPAN&gt;&amp;gt;
        &amp;lt;TextBlock Name=&lt;SPAN class=""&gt;"FilePathTb"&lt;/SPAN&gt; Text=&lt;SPAN class=""&gt;"{Binding TargetFilePath}"&lt;/SPAN&gt;&amp;gt;&amp;lt;/TextBlock&amp;gt;
    &amp;lt;/Grid&amp;gt;

    &amp;lt;WindowsFormsHost MinWidth=&lt;SPAN class=""&gt;"500"&lt;/SPAN&gt; MinHeight=&lt;SPAN class=""&gt;"400"&lt;/SPAN&gt; &amp;gt;
        &amp;lt;Gui:GsPreviewCtrl x:Name=&lt;SPAN class=""&gt;"GsPreviewCtrl"&lt;/SPAN&gt;/&amp;gt;
    &amp;lt;/WindowsFormsHost&amp;gt;

&amp;lt;/DockPanel&amp;gt;&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;Win Form Control itself.&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;GsPreviewCtrl&lt;/SPAN&gt; : &lt;SPAN class=""&gt;Control&lt;/SPAN&gt;
{
    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;region&lt;/SPAN&gt; Fields&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;// current dwg&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; Database mCurrentDwg;

    &lt;SPAN class=""&gt;// Gs specific&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; Manager MpManager;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; Device  mpDevice;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; Model   mpModel;

    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; View mpView;

    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;static&lt;/SPAN&gt; &lt;SPAN class=""&gt;bool&lt;/SPAN&gt; IsDesignMode =&amp;gt; UserControls.Utils.IsDesignMode(&lt;SPAN class=""&gt;null&lt;/SPAN&gt;);

    &lt;SPAN class=""&gt;// A list of other properties and methods to render the object on the device.&lt;/SPAN&gt;
    .....
}&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;A helper method to tell if the Winform control is in design mode or not.&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;static&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;Utils&lt;/SPAN&gt;
{
    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;region&lt;/SPAN&gt; Static Fields&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;endregion&lt;/SPAN&gt;&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;region&lt;/SPAN&gt; Static Properties&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;static&lt;/SPAN&gt; &lt;SPAN class=""&gt;bool&lt;/SPAN&gt; DesignMode { &lt;SPAN class=""&gt;get&lt;/SPAN&gt;; } = &lt;SPAN class=""&gt;string&lt;/SPAN&gt;.Equals(
        Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule?.FileName),
        &lt;SPAN class=""&gt;"devenv"&lt;/SPAN&gt;,
        StringComparison.OrdinalIgnoreCase
    );

    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;endregion&lt;/SPAN&gt;&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;region&lt;/SPAN&gt; Static Methods&lt;/SPAN&gt;

    &lt;SPAN class=""&gt;&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;static&lt;/SPAN&gt; &lt;SPAN class=""&gt;bool&lt;/SPAN&gt; &lt;SPAN class=""&gt;IsDesignMode&lt;/SPAN&gt;(&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;this&lt;/SPAN&gt; Control control&lt;/SPAN&gt;)&lt;/SPAN&gt; { &lt;SPAN class=""&gt;return&lt;/SPAN&gt; DesignMode; }

    &lt;SPAN class=""&gt;#&lt;SPAN class=""&gt;endregion&lt;/SPAN&gt;&lt;/SPAN&gt;
}&lt;/PRE&gt;&lt;P&gt;However, the helper method doesn't tell if the object is in design mode or not. This piece of code comes from the original post from AutoDesk Dev Blog.&lt;/P&gt;&lt;P&gt;&lt;A href="https://adndevblog.typepad.com/autocad/2014/12/drawing-preview-in-wpf-palette.html" target="_blank" rel="nofollow noopener noreferrer"&gt;https://adndevblog.typepad.com/autocad/2014/12/drawing-preview-in-wpf-palette.html&lt;/A&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;The error itself:&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://i.stack.imgur.com/Uy0Zu.png" border="0" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 21:30:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/prevent-user-control-to-be-rendered-in-design-mode/m-p/11752010#M9990</guid>
      <dc:creator>gary.wuEQ8E4</dc:creator>
      <dc:date>2023-02-13T21:30:24Z</dc:date>
    </item>
  </channel>
</rss>

