<?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 Re: Visual Studio 2017 C# .net WPF within Autocad in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8469384#M25143</link>
    <description>&lt;P&gt;Still not sure to understand, but try:&lt;/P&gt;
&lt;PRE&gt;Height="100" Width="50" ResizeMode="NoResize"&amp;gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 14 Dec 2018 20:14:46 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2018-12-14T20:14:46Z</dc:date>
    <item>
      <title>Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8178020#M25136</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using AutoCAD Mechanical 2016, and Visual Studio 2017 (.net C#).&lt;/P&gt;&lt;P&gt;I have some code that I would like to use a WPF within AutoCAD to control.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried looking for some AutoCAD WPF tutorials with .net but all of them seem to be missing the basic introduction to it.&lt;/P&gt;&lt;P&gt;The link below is a good example of how to accomplish this task..but when I try to utilize this example I get a few issues with it.&lt;/P&gt;&lt;P&gt;&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2014/05/adding-a-wpf-document-tab-in-autocad-2015-using-net.html" target="_blank"&gt;http://through-the-interface.typepad.com/through_the_interface/2014/05/adding-a-wpf-document-tab-in-autocad-2015-using-net.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The main issue is, when the palette shows, it is just a blank box and doesn't show a button I added or any of the stuff the example showed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My main question is:&lt;/P&gt;&lt;P&gt;Is there a really good recent example that shows the most basic uses utilizing a WPF within AutoCAD?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 00:03:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8178020#M25136</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-05T00:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8178136#M25137</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To add a WPF modal dialog to your AutoCAD plugin project, you have to add a "User Control (WPF)" to the project and replace Usercontrol with Window in both the xaml and xaml.cs files.&lt;/P&gt;
&lt;P&gt;Here's a minimalist example:&lt;/P&gt;
&lt;P&gt;XAML:&lt;/P&gt;
&lt;PRE&gt;&amp;lt;Window x:Class="SimpleWpfModalDialog.ModalDialog"
             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:SimpleWpfModalDialog"
             mc:Ignorable="d" Height="160" Width="300"&amp;gt;
    &amp;lt;Grid Background="WhiteSmoke"&amp;gt;
        &amp;lt;Grid.RowDefinitions&amp;gt;
            &amp;lt;RowDefinition Height="Auto"/&amp;gt;
            &amp;lt;RowDefinition Height="Auto"/&amp;gt;
            &amp;lt;RowDefinition Height="Auto"/&amp;gt;
        &amp;lt;/Grid.RowDefinitions&amp;gt;
        &amp;lt;Label Grid.Row="0" Margin="5"&amp;gt;Enter your name:&amp;lt;/Label&amp;gt;
        &amp;lt;TextBox x:Name="nameBox" Grid.Row="1" Margin="5"/&amp;gt;
        &amp;lt;Button x:Name="okButton" Grid.Row="2" Margin="10" HorizontalAlignment="Center" Content="OK" Height="24" Width="80" Click="okButton_Click"/&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/Window&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;Code behind (xaml.cs)&lt;/P&gt;
&lt;PRE&gt;using System.Windows;

namespace SimpleWpfModalDialog
{
    public partial class ModalDialog : Window
    {
        public ModalDialog()
        {
            InitializeComponent();
        }

        public string UserName =&amp;gt; nameBox.Text;

        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;To display the dialog box from an AutoCAD command, you have to use the Application.ShowModalWindow() method.&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices.Core;
using Autodesk.AutoCAD.Runtime;

namespace SimpleWpfModalDialog
{
    public class Commands
    {
        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var dialog = new ModalDialog();
            var result = Application.ShowModalWindow(dialog);
            if (result.Value)
                Application.ShowAlertDialog("Hello " + dialog.UserName);
        }
    }
}&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Aug 2018 06:56:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8178136#M25137</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-08-05T06:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8178142#M25138</link>
      <description>&lt;P&gt;To add a WPF modeless dialog (typically a PaletteSet) to your AutoCAD plugin project, you have to add a "User Control (WPF)" to the project.&lt;/P&gt;
&lt;P&gt;XAML:&lt;/P&gt;
&lt;PRE&gt;&amp;lt;UserControl x:Class="SimpleWpfPalette.PaletteUserControl"
             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:SimpleWpfPalette"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800"&amp;gt;
    &amp;lt;Grid Background="WhiteSmoke"&amp;gt;
        &amp;lt;Grid.RowDefinitions&amp;gt;
            &amp;lt;RowDefinition Height="Auto"/&amp;gt;
            &amp;lt;RowDefinition Height="Auto"/&amp;gt;
            &amp;lt;RowDefinition Height="Auto"/&amp;gt;
        &amp;lt;/Grid.RowDefinitions&amp;gt;
        &amp;lt;Label Grid.Row="0" Margin="5"&amp;gt;Enter your name:&amp;lt;/Label&amp;gt;
        &amp;lt;TextBox x:Name="nameBox" Grid.Row="1" Margin="5"/&amp;gt;
        &amp;lt;Button x:Name="okButton" Grid.Row="2" Margin="10" HorizontalAlignment="Center" Content="OK" Height="24" Width="80" Click="okButton_Click"/&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/UserControl&amp;gt;&lt;/PRE&gt;
&lt;P&gt;in the code behind, you can call a custom AutoCAD command with sendStringToExecute to avoid ahaving to lock the current document and set the focus to AutoCAD application:&lt;/P&gt;
&lt;PRE&gt;using System.Windows;
using System.Windows.Controls;

using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace SimpleWpfPalette
{
    public partial class PaletteUserControl : UserControl
    {
        public PaletteUserControl()
        {
            InitializeComponent();
        }

        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
                doc.SendStringToExecute("HELLO " + nameBox.Text + "\n", false, false, false);
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;You add to your project a class for your custom palette set which derives from PaletteSet in which you add the Usercontrol using the AddVisual() method.&lt;/P&gt;
&lt;PRE&gt;using System;

using Autodesk.AutoCAD.Windows;

namespace SimpleWpfPalette
{
    public class CustomPalette : PaletteSet
    {
        public CustomPalette()
            : base("WPF Palette", "SHOW_PALETTE", new Guid("{1E20F389-33C1-421F-81CB-B3D413E5B05C}"))
        {
            Style = PaletteSetStyles.ShowAutoHideButton |
                    PaletteSetStyles.ShowCloseButton |
                    PaletteSetStyles.ShowPropertiesMenu;
            MinimumSize = new System.Drawing.Size(250, 150);
            AddVisual("Hello", new PaletteUserControl());
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;From an AutoCAD command you show the palette (and create it if it not already exists). this class also contains the command called from the button in the palette.&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices.Core;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace SimpleWpfPalette
{
    public class Commands
    {
        static CustomPalette palette;

        [CommandMethod("SHOW_PALETTE")]
        public static void ShowPalette()
        {
            if (palette == null)
                palette = new CustomPalette();
            palette.Visible = true;
        }

        [CommandMethod("Hello")]
        public static void Hello()
        {
            var ed = Application.DocumentManager.MdiActiveDocument.Editor;
            var pr = ed.GetString("\nEnter your name: ");
            if (pr.Status == PromptStatus.OK)
                Application.ShowAlertDialog("Hello " + pr.StringResult);
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 07:06:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8178142#M25138</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-08-05T07:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8178375#M25139</link>
      <description>&lt;P&gt;Exactly what I was looking for!&amp;nbsp; Thank you very much.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 14:36:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8178375#M25139</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-05T14:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8469055#M25140</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; mc:Ignorable="d" Height="100" Width="50"&amp;gt;&lt;/PRE&gt;
&lt;P&gt;the window has a fixed height and width, even with the new value (100,50)&lt;/P&gt;
&lt;P&gt;any help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 17:26:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8469055#M25140</guid>
      <dc:creator>essam-salah</dc:creator>
      <dc:date>2018-12-14T17:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8469186#M25141</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3650456"&gt;@essam-salah&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;HI&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; mc:Ignorable="d" Height="100" Width="50"&amp;gt;&lt;/PRE&gt;
&lt;P&gt;the window has a fixed height and width, even with the new value (100,50)&lt;/P&gt;
&lt;P&gt;any help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sorry, I do not understand your question.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 18:27:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8469186#M25141</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-12-14T18:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8469235#M25142</link>
      <description>I want the window to be smaller&lt;BR /&gt;</description>
      <pubDate>Fri, 14 Dec 2018 18:52:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8469235#M25142</guid>
      <dc:creator>essam-salah</dc:creator>
      <dc:date>2018-12-14T18:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8469384#M25143</link>
      <description>&lt;P&gt;Still not sure to understand, but try:&lt;/P&gt;
&lt;PRE&gt;Height="100" Width="50" ResizeMode="NoResize"&amp;gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Dec 2018 20:14:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8469384#M25143</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-12-14T20:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8470051#M25144</link>
      <description>&lt;P&gt;sir&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;i have a problem but its related to c# more than .NET if u can help.&lt;/P&gt;
&lt;P&gt;i wanna link a wpf control&amp;nbsp; event(combobox1_selectionchanged) to main code in the transaction&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; public partial class ModalDialog : Window
    {
        public ModalDialog()
        {
            InitializeComponent();
        }

        private void Combobox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //textblock1.Text  = somthingFromTransAction; // ????
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Dec 2018 12:20:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8470051#M25144</guid>
      <dc:creator>essam-salah</dc:creator>
      <dc:date>2018-12-15T12:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8470133#M25145</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3650456"&gt;@essam-salah&lt;/a&gt;, Please start a new thread to ask your question because it is different from the OP.&lt;/P&gt;
&lt;P&gt;And try to be more clear and detailed in your request if you want someone to be able to reply you.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Dec 2018 14:09:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8470133#M25145</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-12-15T14:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8860230#M25146</link>
      <description>&lt;P&gt;Hi Gilles&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your answer. Not just this answer, but all the answers on the forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Re: the above code, when the ok button is clicked, the Dialog Result is set to true. Was wondering if you knew a MVVM way to handle this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;When the button is clicked a command should fire; and when this command runs, it should somehow close the window. In this case, the ViewModel should not know anything about the view. Is there a way to handle this?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; public class OverWritePanelsViewModel 
    {
       
        public OverWritePanelsViewModel()
        {
        }

        private ICommand _endCommand;

        public ICommand EndCommand
        {
            get
            {
                if (_endCommand == null)
                {
                    _endCommand = new RelayCommand(
                        p =&amp;gt; { // what should go here to close the window? },
                        p =&amp;gt; { return true; }
                        );
                }
                return _endCommand;
            }
        }
    }

/// And here is my XAML:

&amp;lt;Window x:Class="BKTools.GrabCopy.OverWrite"
             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:BKTools.Tools.GrabCopy"               
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="800"&amp;gt;
    &amp;lt;Grid&amp;gt;
        &amp;lt;StackPanel &amp;gt;
            &amp;lt;Button Command="{Binding EndCommand}"&amp;gt; Ok&amp;lt;/Button&amp;gt;
        &amp;lt;/StackPanel&amp;gt;        
    &amp;lt;/Grid&amp;gt;
&amp;lt;/Window&amp;gt;


&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 13:19:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8860230#M25146</guid>
      <dc:creator>BKSpurgeon</dc:creator>
      <dc:date>2019-06-19T13:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8860574#M25147</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3011731"&gt;@BKSpurgeon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even implementing MVVM, you can use the code behind for a modal dialog box OK button which only set the DialogResult to true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 15:05:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8860574#M25147</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-06-19T15:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8860720#M25148</link>
      <description>&lt;P&gt;You can bind the Window itself to the command as CommandParameter in the XAML, like this&lt;/P&gt;
&lt;P&gt;&amp;lt;Window x:Name="MyDialog" x:Class=... ...&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;lt;Grid&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;Button Content="OK" Width=100 Height=20&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Command="{Binding EndCommand}&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CommandParameter="{Binding ElementName=MyDialog}" /&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;lt;/Grid&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;/Window&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then in the ViewModel, you have the command like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_endCommand=new relayCommand(&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;p =&amp;gt; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var win=(System.Windows.Window)p;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// You can either set the window's DialogResult value&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;win.DialogResult=true/false;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Or you can expose a ViewModel's public property to desired value&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// if the ViewModel remains for next step to get data manipulated by the UI after the view is closed,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// this property would indicate if the view is cancelled or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// then you can close/hide the view, regardless the DialogResult value&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;this.DataOked =&amp;nbsp; true;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;win.Close()/Hide();&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;p =&amp;gt; { return true; });&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The point is that the command parameter is bound to the view Window object, so it can close it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 15:40:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8860720#M25148</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2019-06-19T15:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8860721#M25149</link>
      <description>&lt;P&gt;If you absolutely want to handle the DialogResult from the ViewModel, you can set the CommandParameter of the button to the Window and use this paramater in the EndCommand&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;XAML&lt;/P&gt;
&lt;PRE&gt;&amp;lt;Button Command="{Binding EndCommand}"
        CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"&amp;gt;Ok&amp;lt;/Button&amp;gt;&lt;/PRE&gt;
&lt;P&gt;ViewModel&lt;/P&gt;
&lt;PRE&gt;public RelayCommand EndCommand =&amp;gt;
    new RelayCommand((dlg) =&amp;gt; { ((OverWrite)dlg).DialogResult = true; }, (_) =&amp;gt; true);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One more time&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt; was faster &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 15:45:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8860721#M25149</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-06-19T15:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8860944#M25150</link>
      <description>&lt;P&gt;Another way could be implementing a Button.IsAccept DependencyProperty (similar to Button.IsCancel) as shown in the first reply of &lt;A href="https://stackoverflow.com/questions/2543014/wpf-dialogresult-declaratively" target="_blank" rel="noopener"&gt;this topic&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 17:04:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8860944#M25150</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-06-19T17:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Studio 2017 C# .net WPF within Autocad</title>
      <link>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8862570#M25151</link>
      <description>&lt;P&gt;Thank you very much &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt; and &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 12:11:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/visual-studio-2017-c-net-wpf-within-autocad/m-p/8862570#M25151</guid>
      <dc:creator>BKSpurgeon</dc:creator>
      <dc:date>2019-06-20T12:11:28Z</dc:date>
    </item>
  </channel>
</rss>

