<?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: WPF Dockable Pane and MVVM with Multiple Documents Open in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/wpf-dockable-pane-and-mvvm-with-multiple-documents-open/m-p/10646089#M23534</link>
    <description>&lt;P&gt;Thank you for the quick response.&amp;nbsp; The ViewActivated event was key to what I need to know how to update the document data, and I hadn't considered using the GetHashCode as the reference key.&amp;nbsp; I do not believe going down the static object route is ultimately going to be beneficial, but helpful to know down the road.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Sep 2021 20:53:31 GMT</pubDate>
    <dc:creator>jasonprichardtcc</dc:creator>
    <dc:date>2021-09-24T20:53:31Z</dc:date>
    <item>
      <title>WPF Dockable Pane and MVVM with Multiple Documents Open</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/wpf-dockable-pane-and-mvvm-with-multiple-documents-open/m-p/10645055#M23532</link>
      <description>&lt;P&gt;I have a conceptual question for those who are experienced with WPF dockable panes with MVVM design pattern.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an application that has the following sequence:&lt;/P&gt;&lt;P&gt;WPF modeless dockable pane stores selection data via text boxes and comboboxes as properties for an application.&lt;/P&gt;&lt;P&gt;The user selects(combobox) or inputs(textbox) the desired properties.&lt;/P&gt;&lt;P&gt;The user clicks a command button on my custom Ribbon.&lt;/P&gt;&lt;P&gt;The application retrieves the information from the viewmodel, and performs the function based on the viewmodel data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To date (which I knew was wrong from the beginning....), I have been storing the viewmodel data in a Singleton instance so that I can consistently retrieve the information from the Revit command.&amp;nbsp; The WPF form is databound to the instance so they remain in sync.&amp;nbsp; This works great provided there are not two different Revit Documents open in the application window.&amp;nbsp; As soon as I move between two different documents, the data in the viewmodel does not stay in sync with the document that I'm working in (obviously....)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel certain I can work this out by storing Revit Document instances and associated viewmodel instances as documents are open using a DocumentOpeneded event.&amp;nbsp; However, I am curious for those who have doing this much longer than I have if there is a good standard of practice / pattern I should consider to ensure viewmodel data can stay in sync with the current Document.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;BR /&gt;Jason&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 12:47:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/wpf-dockable-pane-and-mvvm-with-multiple-documents-open/m-p/10645055#M23532</guid>
      <dc:creator>jasonprichardtcc</dc:creator>
      <dc:date>2021-09-24T12:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: WPF Dockable Pane and MVVM with Multiple Documents Open</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/wpf-dockable-pane-and-mvvm-with-multiple-documents-open/m-p/10645286#M23533</link>
      <description>&lt;P&gt;I would use instances with an active instance for the viewmodel set after UIApplication.ViewActivated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would only store in the viewmodel non-Revit items or ElementIds to Revit items i.e. I would re-fetch the Revit data from the model not store it out of context.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Document.GetHashCode can be used to link the right instance of your viewmodel to the active document. If you are using viewmodel instances then setting one as the main DataContext will save a lot of binding work. Not sure you could so easily achieve the same if it were a static object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/27880492/can-i-set-a-datacontext-to-a-static-class" target="_blank" rel="noopener"&gt;In this example&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;TextBlock Text="{Binding Source={x:Static pi:ProgramInfo.ProgramName}}" /&amp;gt;&lt;/P&gt;&lt;P&gt;Reduces to&lt;/P&gt;&lt;P&gt;&amp;lt;TextBlock Text="{Binding ProgramName}" /&amp;gt;&lt;/P&gt;&lt;P&gt;If overall DataContext points to for example 'ActiveViewModel' instance or static property returning an instance of type viewmodel.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 14:53:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/wpf-dockable-pane-and-mvvm-with-multiple-documents-open/m-p/10645286#M23533</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2021-09-24T14:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: WPF Dockable Pane and MVVM with Multiple Documents Open</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/wpf-dockable-pane-and-mvvm-with-multiple-documents-open/m-p/10646089#M23534</link>
      <description>&lt;P&gt;Thank you for the quick response.&amp;nbsp; The ViewActivated event was key to what I need to know how to update the document data, and I hadn't considered using the GetHashCode as the reference key.&amp;nbsp; I do not believe going down the static object route is ultimately going to be beneficial, but helpful to know down the road.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 20:53:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/wpf-dockable-pane-and-mvvm-with-multiple-documents-open/m-p/10646089#M23534</guid>
      <dc:creator>jasonprichardtcc</dc:creator>
      <dc:date>2021-09-24T20:53:31Z</dc:date>
    </item>
  </channel>
</rss>

