Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3605920
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:11:02+00:00 2026-05-18T21:11:02+00:00

I am reading one book which says Rather than setting the DialogResult by hand

  • 0

I am reading one book which says

Rather than setting the DialogResult
by hand after the user clicks a
button, you can designate a button as
the accept button (by setting
IsDefault to true). Clicking that
button automatically sets the
DialogResult of the window to true.
Similarly, you can designate a button
as the cancel button (by setting
IsCancel to true), in which case
clicking it will set the DialogResult
to Cancel.

This is the MainWindow:

<Window x:Class="WpfApplicationWPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Width="400" Height="400">
    <StackPanel>

        <Button Name="BtnShowDialogStatus" Click="BtnShowDialogStatus_Click">DIALOG RESULT</Button>
    </StackPanel>
</Window>

Code for click event:

private void BtnShowDialogStatus_Click(object sender, RoutedEventArgs e)
{
    MessageBox.Show(new NewWindow().ShowDialog().ToString());
}

And this is the Dialog box which I am opening on the click event:

<Window x:Class="WpfApplicationWPF.NewWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="NewWindow" Height="300" Width="300">
    <StackPanel>
        <Button Name="BtnDEfault" IsDefault="True" Click="BtnDEfault_Click">DEFAULT BUTTON</Button>
        <Button Name="BtnCancel" IsCancel="True" Click="BtnCancel_Click">CANCEL BUTTON</Button>
    </StackPanel>
</Window>   

This is the code for it:

private void BtnDEfault_Click(object sender, RoutedEventArgs e)
{
    this.Close();
}

private void BtnCancel_Click(object sender, RoutedEventArgs e)
{
    this.Close();
}

I can see it returning the DialogResult only as false no matter I click the default or cancel button.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:11:03+00:00Added an answer on May 18, 2026 at 9:11 pm

    IsDefault ties the button to the Enter key, so that pressing the Enter key will fire the Click event. It does not mean that the Yes button will return true for the DialogResult.

    Refer to the links.It will clear up things for you

    http://blog.wpfwonderland.com/2010/03/22/getting-a-dialogresult-from-a-wpf-window/

    http://www.wpftutorial.net/Dialogs.html

    Hope it helps…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one application which is reading outlook mail, but when user install
I'm reading Douglas Crockford's book JavaScript: The Good Parts. I can't understand the sentence
So I am reading this book titled Java Concurrency in Practice and I am
I've been reading up on PHP lately and Validation of user input is a
I am reading Java Concurrency in Practice and kind of confused with the thread
I'm in a group at work reading Seven Languages in Seven Weeks by Bruce
I have the following javascript : var MyObject = (function() { function Setup(args) {
Given a declared PLSQL Procedure PROCEDURE GET_DISTINCT_TIMES(dtypes IN VARCHAR2, start IN NUMBER, end IN
I was wondering what is better in this case? I have to read in
Here is the result of a profiled simulation run of my MATLAB program. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.