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 6795455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:20:51+00:00 2026-05-26T18:20:51+00:00

I am building a WPF application using C#. I want to pop out a

  • 0

I am building a WPF application using C#. I want to pop out a dialog box to prompt the user to enter his/her name. After that, I will keep track of the name and save some data into a .txt file using the name.

For example:

Name input is
name = "John"

And so I have data
data="1, 2, 3";

and then I save the "data" in John.txt file.

Does anyone know how to do it?

I think the problem is how to pop out a dialog for the user to enter name.

  • 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-26T18:20:51+00:00Added an answer on May 26, 2026 at 6:20 pm

    I prefer to take an approach using dialogs that doesn’t lock up the application, and moves away from the more traditional Win32 Dialog.

    Example

    Input Dialog

    Input Dialog Hidden

    Input Dialog not showing.

    In this example I use a simplified version of the MVVM based solution I am using for my applications. It may not be pretty, but should give you a solid idea on the basics behind it.

    The XAML:

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel>
            <Button Content="Cool Button" x:Name="CoolButton" Click="CoolButton_Click"/>
            <ListBox x:Name="MyListBox"/>
        </StackPanel>
        
        <!-- It's important that this is in the end of the XAML as it needs to be on top of everything else! -->
        <Grid x:Name="InputBox" Visibility="Collapsed">
            <Grid Background="Black" Opacity="0.5"/>
                <Border
                    MinWidth="250"
                    Background="Orange" 
                    BorderBrush="Black" 
                    BorderThickness="1" 
                    CornerRadius="0,55,0,55" 
                    HorizontalAlignment="Center" 
                    VerticalAlignment="Center">
                    <StackPanel>
                        <TextBlock Margin="5" Text="Input Box:" FontWeight="Bold" FontFamily="Cambria" />
                        <TextBox MinWidth="150" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="InputTextBox"/>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                            <Button x:Name="YesButton" Margin="5" Content="Yes" Background="{x:Null}" Click="YesButton_Click"/>
                            <Button x:Name="NoButton" Margin="5" Content="No" Background="{x:Null}" Click="NoButton_Click" />
                        </StackPanel>
                    </StackPanel>
                </Border>
            </Grid>
        </Grid>
    </Window>
    

    It’s very easy to show this dialog as you only need to set the Visibility of the InputBox grid to visible. You then simply handle the Yes / No buttons and get the Input text from the TextBox.

    So instead of using code that requires ShowDialog(), you simply set the Visibility option to Visible. There are still some things to do in this example that we will handle in code-behind, like for example clearing the InputText box after handling the Yes/No Button clicks.

    The code-behind:

    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void CoolButton_Click(object sender, RoutedEventArgs e)
            {
                // CoolButton Clicked! Let's show our InputBox.
                InputBox.Visibility = System.Windows.Visibility.Visible;
            }
    
            private void YesButton_Click(object sender, RoutedEventArgs e)
            {
                // YesButton Clicked! Let's hide our InputBox and handle the input text.
                InputBox.Visibility = System.Windows.Visibility.Collapsed;
    
                // Do something with the Input
                String input = InputTextBox.Text;
                MyListBox.Items.Add(input); // Add Input to our ListBox.
    
                // Clear InputBox.
                InputTextBox.Text = String.Empty;
            }
    
            private void NoButton_Click(object sender, RoutedEventArgs e)
            {
                // NoButton Clicked! Let's hide our InputBox.
                InputBox.Visibility = System.Windows.Visibility.Collapsed;
    
                // Clear InputBox.
                InputTextBox.Text = String.Empty;
            }
        }
    }
    

    The code-behind could easily be done using a Dependency, or as ViewModel logic in this case, but for simplicity I kept it in the code-behind.

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

Sidebar

Related Questions

We were building out the next version of an in-house thick-client application using WPF/Prism
I'm building an application in C# using WPF. How can I bind to some
I am building a WPF application and I want its background to be filled
I’m building a WPF application using MVVM pattern (both are new technologies for me).
I am using the Model-View-ViewModel architecture in a WPF application I am building, and
I am building a WPF application using C# 3.5 I have a WPF menu
I am building a WPF Application using C# in VS 2008/.NET 3.5 SP1. I
I am building a WPF 4.0 Application using MVVM. The Model is generated using
I'm building simple dictionary application using WPF. I'm using MVVM pattern, databinding and FlowDocument
I am building a WPF application in C# and I want to display thumbnails

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.