Modal WPF dialog

Modal WPF dialog

SENL1362
Advisor Advisor
3,270 Views
5 Replies
Message 1 of 6

Modal WPF dialog

SENL1362
Advisor
Advisor

I'll use WPF UserControls in Palettes for all my non blocking(modeless) dialogs however i can't get a Model dialog designed in WPF.

AS a workaround i'll use a Windows Form containing ElementHost to load a UserControl but this gives me sometimes  issues in VS 2015 -- didn't tried Vs2017 yet.

 

I'll need a simple WPF dialog, asking the user a question which he must answer before continuing.

 

Thanks for any help.

 

 

0 Likes
Accepted solutions (1)
3,271 Views
5 Replies
Replies (5)
Message 2 of 6

Virupaksha_aithal
Autodesk Support
Autodesk Support

Hi,

 

Please use Autodesk.AutoCAD.ApplicationServices.Application.ShowModalWindow() to show the WPF dialog as modal dialog.



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 6

SENL1362
Advisor
Advisor

 

Hello Virupaksha,

At first i should am i that stupid but fortunately there is more on to it Smiley Embarassed

This is my problem, you cannot add a (WPF) UserControl directly. Somesort of canvas is required, such as a Palette or Form with ElementHost.

 

What is needed to do show this UserControl1 as a modal dialog

 

                var modUc = new UserControl1();
                AcadApp.ShowModalWindow(modUc);  //cannot convert...

Thank you for any help.

 

 

<UserControl x:Class="TestAcadUpdate.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:TestAcadUpdate"
             mc:Ignorable="d" Height="auto" Width="auto" MinHeight="200" MinWidth="250" d:DesignHeight="200" d:DesignWidth="250">

    <Grid Name="grdMain" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="30*" />
            <RowDefinition Name="ChkAllRow" Height="30*" />
            <RowDefinition Height="80*" />
            <RowDefinition Height="30*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120*" />
            <ColumnDefinition Width="120*" />
        </Grid.ColumnDefinitions>

    

        <Grid Grid.Row="0" Grid.Column="0" >
            <Label Name="lblDwgName" Content="DrawingX.dwg" HorizontalAlignment="Left" VerticalAlignment="Top" MinWidth="100" MaxWidth="250"  MinHeight="20" MaxHeight="50"  Margin="5"/>
        </Grid>

        <Grid Grid.Row="0" Grid.Column="1" >
            <Label Name="lblTitle" Content="..." HorizontalAlignment="Left" VerticalAlignment="Top" MinWidth="100" MaxWidth="250"  MinHeight="20" MaxHeight="50"  Margin="5"/>
        </Grid>

        <CheckBox Grid.Row="1"    Name="ChkAll" Content="SelectAll" Click="ChkAll_Click" IsThreeState="False"  Height="20"  Margin="6,3,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="103"/>

        <ListBox Grid.Row="2" Grid.ColumnSpan="2" Name="LstBox" Margin="5" SelectionMode="Single" SelectionChanged="LstBox_SelectionChanged" ScrollViewer.VerticalScrollBarVisibility="Visible"/>

        <Grid  Grid.Row="3" Grid.ColumnSpan="2" >
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"  >
                <Button  Name="btnOk" Content="OK"  MinWidth="100" MaxWidth="250"  MinHeight="20" MaxHeight="50"   Margin="5"  Click="btnOk_Click"/>
                <Button  Name="btnCancel" Content="Cancel"  MinWidth="100" MaxWidth="250" MinHeight="20" MaxHeight="50"    Margin="5" IsCancel="True"   Click="btnCancel_Click"/>
            </StackPanel>
        </Grid>

    </Grid>
</UserControl>
0 Likes
Message 4 of 6

_gile
Consultant
Consultant
Accepted solution

Hi

 

You can replace "UserControl" with "Window" in the xaml and xaml.cs files.

 

If you can understand French (or use an in line translator), you can see this tutorial about AutoCAD user interfaces with .NET.

 

 

By my side, I made a basic template for an AutoCAD WPF modal dialog using MVVM (see attached) which automatically launches AutoCAD (currently 2014) and loads the DLL when debugging from Visual Studio.

 

The "AutoCAD WPF Dialog.zip" have to pasted in the Visual Studio 2015 Project Templates folder, default:

Documents\Visual Studio 2015\Templates\ProjectTemplates

or in one of its subfoder (you can create an AutoCAD sub folder):

Documents\Visual Studio 2015\Templates\ProjectTemplates\Visual C#\AutoCAD

 

You'd probably have to edit the AcadWpfDialog.csproj in the ZIP file to change the paths of the StartProgram, currently:

<StartProgram>C:\Program Files\Autodesk\AutoCAD 2014\acad.exe</StartProgram>

 

and those or the AutoCAD libraries, currently:

<HintPath>C:\ObjectARX 2013\inc\AcCoreMgd.dll</HintPath>

<HintPath>C:\ObjectARX 2013\inc\AcDbMgd.dll</HintPath>

<HintPath>C:\ObjectARX 2013\inc\AcMgd.dll</HintPath>

 

You'd also edit the My Template.vstemplate if you want to target another .NET Framework than 4.0:

<RequiredFrameworkVersion>4.0</RequiredFrameworkVersion>



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 6

SENL1362
Advisor
Advisor
Hello Gile,
Although not living far from Frans my knowledge of the language is limited to OUI, NO and SUPURB, which qualifies to you.
As usual we own you a lot credits.

I give it a try.
Thanks again
0 Likes
Message 6 of 6

SENL1362
Advisor
Advisor

OUI, it worked, all it required was changing UserControl into Window and add a few references  . You made my day. ThumpsUp

 

 

0 Likes