<?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 : Autocad API.. Data bindinding does not work in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6225612#M36728</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not know what you're trying to do but it looks like you want to implement MVVM design pattern.&lt;/P&gt;
&lt;P&gt;In MVVM, the View only interacts with the ViewModel so the simplest way is to set the Device property default value in the MainViewModel constructor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Public Class MainViewModel&lt;BR /&gt;    Implements InotitfyPropertyChanged&lt;BR /&gt;&lt;BR /&gt;    Public Sub New()
        Me.Device = "Schneider"
    End Sub&lt;BR /&gt;&lt;BR /&gt;    ,...&lt;BR /&gt;End Class&lt;/PRE&gt;
&lt;P&gt;If you need to get the Device value from elsewhere (i.e. the Mode partl), you need to make it accessible from the Model to the ViewModel.&lt;/P&gt;
&lt;P&gt;Typically the ViewModel creates an instance of Model class and get the data from a property of this instance. If the data may change, the Model may raise some events to notify the changes to the ViewModel.&lt;/P&gt;
&lt;P&gt;But this seems to be useless complexification for a such simple task...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some links about MVVM:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/hh848246.aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/hh848246.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/ff798384.aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/ff798384.aspx&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Mar 2016 07:08:39 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2016-03-21T07:08:39Z</dc:date>
    <item>
      <title>Autocad API.. Data bindinding does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6224745#M36725</link>
      <description>&lt;P&gt;I am trying from several days to try to make it work but I could not.. Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My xaml&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;UserControl x:Class="PN_NO"&lt;BR /&gt;xmlns="&lt;A href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;" target="_blank"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/A&gt;&lt;BR /&gt;xmlns:x="&lt;A href="http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;" target="_blank"&gt;http://schemas.microsoft.com/winfx/2006/xaml"&lt;/A&gt;&lt;BR /&gt;&amp;nbsp;xmlns:mc="&lt;A href="http://schemas.openxmlformats.org/markup-compatibility/2006&amp;quot;" target="_blank"&gt;http://schemas.openxmlformats.org/markup-compatibility/2006"&lt;/A&gt;&lt;BR /&gt;&amp;gt;&lt;BR /&gt;xmlns:d="&lt;A href="http://schemas.microsoft.com/expression/blend/2008&amp;quot;" target="_blank"&gt;http://schemas.microsoft.com/expression/blend/2008"&lt;/A&gt;&lt;BR /&gt;xmlns:local="clr-namespace:SchneiderMacros"&lt;BR /&gt;mc:Ignorable="d"&lt;BR /&gt;d:DesignHeight="300" d:DesignWidth="300"&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;UserControl.DataContext &amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;lt;local:mainviewmodel &amp;gt;&amp;lt;/local:mainviewmodel&amp;gt;&lt;BR /&gt;&amp;lt;/UserControl.DataContext&amp;gt;&lt;BR /&gt;&amp;lt;Grid Background="#FF2D2D30"&amp;gt;&lt;BR /&gt;&amp;lt;StackPanel &amp;gt;&lt;BR /&gt;&amp;lt;TextBox Height=" 30" Text="{Binding device}" Margin=" 10"&amp;gt;&amp;lt;/TextBox&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;lt;/StackPanel&amp;gt;&lt;BR /&gt;&lt;BR /&gt;&amp;lt;/Grid&amp;gt; &amp;lt;/UserControl&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My view class&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Class PNWPFPalette&lt;/P&gt;&lt;P&gt;Public devicelocaton As String&lt;BR /&gt;Shared _PS1 As PaletteSet = Nothing&lt;BR /&gt;Public Sub ShowPNWPFPalette()&lt;/P&gt;&lt;P&gt;If _PS1 Is Nothing Then&lt;BR /&gt;_PS1 = New PaletteSet("Modify Attributes")&lt;BR /&gt;_PS1.Size = New Size(400, 600)&lt;BR /&gt;_PS1.DockEnabled = DirectCast(CInt(DockSides.Left) + CInt(DockSides.Right), DockSides)&lt;BR /&gt;Dim uc1 As New PN_NO&lt;BR /&gt;'_PS1.AddVisual("Update PN", uc1)&lt;BR /&gt;Dim host As ElementHost = New ElementHost&lt;BR /&gt;host.AutoSize = True&lt;BR /&gt;host.Dock = DockStyle.Fill&lt;BR /&gt;host.Child = uc1&lt;BR /&gt;_PS1.Add("Modify PN", host)&lt;BR /&gt;Dim uc2 As New PN_NO&lt;BR /&gt;Dim host1 As ElementHost = New ElementHost&lt;BR /&gt;host1.AutoSize = True&lt;BR /&gt;host1.Dock = DockStyle.Fill&lt;BR /&gt;host1.Child = uc2&lt;BR /&gt;_PS1.Add("Modify PN2", host1)&lt;BR /&gt;End If&lt;BR /&gt;_PS1.KeepFocus = True&lt;BR /&gt;_PS1.Visible = True&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Public Function findattributes()&lt;BR /&gt;Dim DL as string = "Pankaj"&lt;BR /&gt;Return DL&lt;BR /&gt;End Function&lt;/P&gt;&lt;P&gt;End Class&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Viewmodel class&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Class mainviewmodel&lt;BR /&gt;Implements INotifyPropertyChanged&lt;/P&gt;&lt;P&gt;Public Property device As String&lt;BR /&gt;Get&lt;BR /&gt;Return _device&lt;BR /&gt;End Get&lt;BR /&gt;Set(value As String)&lt;BR /&gt;_device = value&lt;BR /&gt;OnPropertyChange("device")&lt;BR /&gt;End Set&lt;BR /&gt;End Property&lt;BR /&gt;Private _device As String&lt;BR /&gt;Protected Sub OnPropertyChange(name As String)&lt;BR /&gt;RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))&lt;BR /&gt;End Sub&lt;BR /&gt;Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged&lt;BR /&gt;End Class&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Class where I am running my commands&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public class mycommands&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;CommandMethod("addPNPalette", CommandFlags.UsePickSet)&amp;gt;&lt;BR /&gt;Public Sub PNPalette()&lt;BR /&gt;Dim addpn As New PNWPFPalette&lt;BR /&gt;Dim viewmodel As New mainviewmodel&lt;BR /&gt;addpn.ShowPNWPFPalette()&lt;BR /&gt;Dim DL As String = addpn.findattributes()&lt;/P&gt;&lt;P&gt;viewmodel.device = "Schneider"&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;End Class&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Afte running command textbox remains blank... Please help.......&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 05:29:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6224745#M36725</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-20T05:29:04Z</dc:date>
    </item>
    <item>
      <title>Re : Autocad API.. Data bindinding does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6225249#M36726</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you set the DataContext of the UserControl to MainViewModel, you implictely create a new instance of MainViewModel class:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;UserControl.DataContext &amp;gt;
     &amp;lt;local:MainViewModel /&amp;gt;
&amp;lt;/UserControl.DataContext&amp;gt;&lt;/PRE&gt;
&lt;P&gt;in PN_NO.xaml is the same as the following PN_NO constructor code&amp;nbsp; in PN_NO.xaml.vb:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Public Sub New()&lt;BR /&gt;    InitializeComponent()
    DataContext = New MainViewModel()
End Sub&lt;/PRE&gt;
&lt;P&gt;So creating a new instance of&amp;nbsp; MainViewModel in the CommandMethod and setting this instance Device property has no effect on the instance bound to the UserControl.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: please use the {i} button to insert code so that if keeps formatted.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 19:43:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6225249#M36726</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-03-20T19:43:52Z</dc:date>
    </item>
    <item>
      <title>Re : Autocad API.. Data bindinding does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6225374#M36727</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile﻿&lt;/a&gt;, thnaks for reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I did not understood, what I need to change then?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 22:55:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6225374#M36727</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-20T22:55:33Z</dc:date>
    </item>
    <item>
      <title>Re : Autocad API.. Data bindinding does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6225612#M36728</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not know what you're trying to do but it looks like you want to implement MVVM design pattern.&lt;/P&gt;
&lt;P&gt;In MVVM, the View only interacts with the ViewModel so the simplest way is to set the Device property default value in the MainViewModel constructor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Public Class MainViewModel&lt;BR /&gt;    Implements InotitfyPropertyChanged&lt;BR /&gt;&lt;BR /&gt;    Public Sub New()
        Me.Device = "Schneider"
    End Sub&lt;BR /&gt;&lt;BR /&gt;    ,...&lt;BR /&gt;End Class&lt;/PRE&gt;
&lt;P&gt;If you need to get the Device value from elsewhere (i.e. the Mode partl), you need to make it accessible from the Model to the ViewModel.&lt;/P&gt;
&lt;P&gt;Typically the ViewModel creates an instance of Model class and get the data from a property of this instance. If the data may change, the Model may raise some events to notify the changes to the ViewModel.&lt;/P&gt;
&lt;P&gt;But this seems to be useless complexification for a such simple task...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some links about MVVM:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/hh848246.aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/hh848246.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/ff798384.aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/ff798384.aspx&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 07:08:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6225612#M36728</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-03-21T07:08:39Z</dc:date>
    </item>
    <item>
      <title>Re : Autocad API.. Data bindinding does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6226006#M36729</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile﻿&lt;/a&gt;&amp;nbsp;thanks for reply to my novice question!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In that case I need to&amp;nbsp;implement property change event in Model and view model both?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you give example of getting data from model and notifying it to UI element in View?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 12:08:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6226006#M36729</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-21T12:08:44Z</dc:date>
    </item>
    <item>
      <title>Re : Autocad API.. Data bindinding does not work</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6227218#M36730</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;As I said&lt;/SPAN&gt; &lt;SPAN&gt;implementing&lt;/SPAN&gt; &lt;SPAN&gt;MVVM&lt;/SPAN&gt; &lt;SPAN&gt;can&lt;/SPAN&gt; &lt;SPAN&gt;make things complicated&lt;/SPAN&gt; &lt;SPAN&gt;especially with a&lt;/SPAN&gt; &lt;SPAN&gt;modeless&lt;/SPAN&gt; &lt;SPAN&gt;palette that&lt;/SPAN&gt; &lt;SPAN&gt;requires&lt;/SPAN&gt; &lt;SPAN&gt;managing&lt;/SPAN&gt; &lt;SPAN&gt;the activation and&lt;/SPAN&gt; &lt;SPAN&gt;creation of new&lt;/SPAN&gt; &lt;SPAN&gt;documents.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a small&lt;/SPAN&gt; &lt;SPAN&gt;example (C#, sorry I don't use VB)&lt;/SPAN&gt; &lt;SPAN&gt;that shows&lt;/SPAN&gt; &lt;SPAN&gt;the current layer&lt;/SPAN&gt; &lt;SPAN&gt;in the palette.&lt;/SPAN&gt; &lt;SPAN&gt;Model&lt;/SPAN&gt;&lt;SPAN&gt;, View&lt;/SPAN&gt; &lt;SPAN&gt;and&lt;/SPAN&gt; &lt;SPAN&gt;ViewModel&lt;/SPAN&gt; &lt;SPAN&gt;are separated&lt;/SPAN&gt; &lt;SPAN&gt;into&lt;/SPAN&gt; &lt;SPAN&gt;different&lt;/SPAN&gt; namespaces.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;The View part:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;XAML&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;UserControl x:Class="AcadWpfPalette.View.PaletteTab"
             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:AcadWpfPalette.View"
             xmlns:viewModel="clr-namespace:AcadWpfPalette.ViewModel"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"&amp;gt;
    &amp;lt;UserControl.DataContext&amp;gt;
        &amp;lt;viewModel:SampleViewModel/&amp;gt;
    &amp;lt;/UserControl.DataContext&amp;gt;
    &amp;lt;StackPanel Background="WhiteSmoke"&amp;gt;
        &amp;lt;Label Margin="5"&amp;gt;Current layer:&amp;lt;/Label&amp;gt;
        &amp;lt;TextBlock Margin="5" Height="30" Text="{Binding Clayer}"/&amp;gt;
    &amp;lt;/StackPanel&amp;gt;
&amp;lt;/UserControl&amp;gt;&lt;/PRE&gt;
&lt;P&gt;C# code for the Palette&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Windows;
using System;

namespace AcadWpfPalette.View
{
    class SamplePalette
    {
        static PaletteSet palette;
        static bool wasVisible;

        public void Show()
        {
            if (palette == null)
            {
                palette = new PaletteSet("SamplePalette", new Guid("{3E405DB6-AA46-4512-B91C-F7914B1440CF}"));
                palette.Style =
                    PaletteSetStyles.ShowAutoHideButton |
                    PaletteSetStyles.ShowCloseButton |
                    PaletteSetStyles.ShowPropertiesMenu;
                palette.MinimumSize = new System.Drawing.Size(200, 240);
                palette.Name = "Sample Palette";
                palette.AddVisual("Sample Control", new PaletteTab());

                // auto hiding on no document state
                var docs = Application.DocumentManager;
                docs.DocumentBecameCurrent += (s, e) =&amp;gt; palette.Visible = e.Document == null ? false : wasVisible;
                docs.DocumentCreated += (s, e) =&amp;gt; palette.Visible = wasVisible;
                docs.DocumentToBeDeactivated += (s, e) =&amp;gt; wasVisible = palette.Visible;
                docs.DocumentToBeDestroyed += (s, e) =&amp;gt;
                {
                    wasVisible = palette.Visible;
                    if (docs.Count == 1) palette.Visible = false;
                };
            }
            palette.Visible = true;
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ViewModel part:&lt;/P&gt;
&lt;PRE&gt;using AcadWpfPalette.Model;
using System.ComponentModel;

namespace AcadWpfPalette.ViewModel
{
    class SampleViewModel : INotifyPropertyChanged
    {
        string clayer;
        AcadModel model;

        public SampleViewModel()
        {
            model = new AcadModel();
            clayer = model.Clayer;
            model.CurrentLayerChanged += Model_CurrentLayerChanged;
        }

        public string Clayer
        {
            get { return clayer; }
            set
            {
                clayer = value;
                RaisePropertyChanged("Clayer");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }

        private void Model_CurrentLayerChanged(object sender, CurrentLayerChangedEventArgs e)
        {
            Clayer = e.Clayer;
        }
    }
}
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Model part:&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using System;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
using AcDb = Autodesk.AutoCAD.DatabaseServices;

namespace AcadWpfPalette.Model
{
    public class AcadModel
    {
        DocumentCollection docs;
        string clayer;

        public AcadModel()
        {
            clayer = (string)AcAp.GetSystemVariable("CLAYER");
            docs = AcAp.DocumentManager;
            foreach (Document doc in docs)
            {
                docs.MdiActiveDocument.Database.SystemVariableChanged += Database_SystemVariableChanged;
            }
            docs.DocumentCreated += Docs_DocumentCreated;
            docs.DocumentActivated += Docs_DocumentActivated;
        }

        public string Clayer
        {
            get { return clayer; }
            private set { clayer = value; }
        }

        public delegate void CurrentLayerChangedEventHandler(object sender, CurrentLayerChangedEventArgs e);

        public event CurrentLayerChangedEventHandler CurrentLayerChanged;

        private void Docs_DocumentActivated(object sender, DocumentCollectionEventArgs e)
        {
            Clayer = (string)AcAp.GetSystemVariable("CLAYER");
            RaiseCurrentLayerChanged();
        }

        private void Docs_DocumentCreated(object sender, DocumentCollectionEventArgs e)
        {
            e.Document.Database.SystemVariableChanged += Database_SystemVariableChanged;
            RaiseCurrentLayerChanged();
        }

        private void Database_SystemVariableChanged(object sender, AcDb.SystemVariableChangedEventArgs e)
        {
            if (e.Name == "CLAYER")
            {
                Clayer = (string)AcAp.GetSystemVariable("CLAYER");
                RaiseCurrentLayerChanged();
            }
        }

        private void RaiseCurrentLayerChanged()
        {
            CurrentLayerChangedEventHandler handler = CurrentLayerChanged;
            if (handler != null)
                handler(this, new CurrentLayerChangedEventArgs(Clayer));
        }
    }

    public class CurrentLayerChangedEventArgs : EventArgs
    {
        public string Clayer { get; }
        public CurrentLayerChangedEventArgs(string clayer) { Clayer = clayer; }
    }
}
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Command to show the Palette:&lt;/P&gt;
&lt;PRE&gt;using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(AcadWpfPalette.Commands))]

namespace AcadWpfPalette
{
    public class Commands
    {
        [CommandMethod("CMD")]
        public void Cmd()
        {
            View.SamplePalette palette = new View.SamplePalette();
            palette.Show();
        }
    }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 21:20:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-api-data-bindinding-does-not-work/m-p/6227218#M36730</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-03-21T21:20:28Z</dc:date>
    </item>
  </channel>
</rss>

