Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From your description it sounds like your code is actually running inside the WPF Designer within Visual Studio, for example it is part of a custom control library that is being used for design.</p> <p>In this case, <code>Assembly.GetEntryAssembly()</code> returns null, but the following code gets the path to the application directory:</p> <pre><code> string applicationDirectory = ( from assembly in AppDomain.CurrentDomain.GetAssemblies() where assembly.CodeBase.EndsWith(".exe") select System.IO.Path.GetDirectoryName(assembly.CodeBase.Replace("file:///", "")) ).FirstOrDefault(); </code></pre> <p>The following steps can be used to demonstrate this works inside VS.NET 2008's WPF Designer tool:</p> <ol> <li>Place this code inside a "WPF Custom Control Library" or "Class Library" project</li> <li>Add whatever code is necessary to read the database and return the data for display (in my case I just returned the application directory itself as a string)</li> <li>Reference the library project from the project you are designing</li> <li>Use the custom controls or classes from a XAML file to populate your DataContext or otherwise supply data to your UI (in my case I bound DataContext using x:Static)</li> <li>Edit that XAML file with the "Windows Presentation Foundation Designer", which can be done by just double-clicking unless you have changed your default editor, in which case use "Open With..."</li> </ol> <p>When you follow these steps, the object you are looking at will be populated with data from your database the same way both at run time and design time.</p> <p>There are other scenarios in which this same technique works just as well, and there are other solutions available depending on your needs. Please let us know if your needs are different those I assumed above. For example, if you are writing a VS.NET add-in, you are in a completely different ball game.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload