Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a WPF window as customized modal import dialog fails on DependencyProperties
    primarykey
    data
    text
    <p>I want to create a customized import dialog and therefore I created a window with some stuff. In order to make this import dialog modal, I'm using the ShowDialog() method. Up to now everything works as expected. My code looks like:</p> <pre><code>var dialogresult = new MyImportDialog().ShowDialog(); if(dialogresult.HasValue &amp;&amp; dialogresult.Value) { Console.WriteLine("Import"); } </code></pre> <p>But when I try to use this dialog twice, got a ArgumentException because my static DependencyProperties got registered a second time. So I tried not to delete my import dialog and use it a second time.</p> <pre><code>private MyImportDialog _myImportDialog; private void OnImportClick(object sender, RoutedEventArgs e) { if (_myImportDialog== null) _myImportDialog= new MyImportDialog (); var dialogresult = _myImportDialog.ShowDialog(); if(dialogresult.HasValue &amp;&amp; dialogresult.Value) { Console.WriteLine("Import"); } } </code></pre> <p>Now I got an InvalidOperationException(Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed.). But the ShowDialog method has an remark: "Opens a window and returns only when the newly opened window is closed."</p> <p>So my next idea was to register for the closing event in my import dialog and then unregister my DependecyProperties. Unfortunately there is no official way doing this. The only thing I found was this: <a href="https://stackoverflow.com/questions/146794/any-way-to-un-register-a-wpf-dependency-property">Any way to un-register a WPF dependency property?</a>.</p> <p>But the solution is (in my opinion) a little bit dirty and the author warned not to use this code in productive environment. </p> <p>So, is there another more cleaner solution to use a modal window twice?</p> <p>Thanking you in anticipation. </p> <p>Edit: This code shows one Dependency Property I'm using:</p> <pre><code>public DependencyProperty ClearProperty = DependencyProperty.Register("Clear", typeof (bool), typeof (MyImportDialog), new PropertyMetadata(true)); /// &lt;summary&gt; /// Indicates whether view should be cleard before importing new image stack. /// &lt;/summary&gt; public bool Clear { get { return (bool) GetValue(ClearProperty); } set { SetValue(ClearProperty, value);} } </code></pre>
    singulars
    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.
 

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