Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Problem with dialog box running twice

$
0
0

Hello all.

I am having trouble to figure out a problem with a dialog box.

I show the dlg from the main menu like this.

 private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            DialogRender dlg = new DialogRender();
            dlg.Owner = this;
            dlg.ShowDialog();

         //from here on the code is not implemented yet

        }

The code in the DialogRender.xaml file is :

<Button x:Name="okButton" DockPanel.Dock="Left"  Click="okButton_Click" Width="40" Height="25">OK</Button>
<Button x:Name="cancelButton"  DockPanel.Dock="Left" IsCancel="True" Width="40" Height="25" Click="cancelButton_Click">Cancel</Button>

and the code for the buttons are :

 private void okButton_Click(object sender, RoutedEventArgs e)

        {
            this.DialogResult = true;
         }
 private void cancelButton_Click(object sender, RoutedEventArgs e)
        {

   this.DialogResult = false;
        }

The problem is that when the Ok or Cancel button is pressed it recreates the dialog box entering a second time in the 

 DialogRender dlg = new DialogRender();
            dlg.Owner = this;
            dlg.ShowDialog();

It means that I always have to press OK or cancel two times to close the dialog box.

Any ideas.

TIA.

Jair Santos


Jair Santos


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>