UWP C# Yes/No pop-up window and one more thing.

VoyTec 671 Reputation points
2022-11-02T19:21:42.077+00:00

Greetings and thank you guys for help so far...

Today I am facing two another issues.

  1. I want to make a pop-up window with yes/no option, and then use the selection into a code.
  2. Another thingy is I am using a NuGet for Number boxes, cause Visual Studio 2022 is lack of it, or am I missing something? And the problem is that this NuGet isn't perfect, in a matter of fact it is really bugged. Is there, a way to find a perfect working box with values only, for calculations?
Developer technologies | Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2022-11-04T07:05:48.383+00:00

    Using NumberBox directly doesn't seem to meet your needs.
    Use Regex like this in the TextBox to delete the character when the user enters non-numeric character.

    Page.xaml

     <TextBox TextChanged="TextBox_TextChanged" />  
    

    Page.xaml.cs

    private void TextBox_TextChanged(object sender, TextChangedEventArgs e)  
        {  
            var textbox = (TextBox)sender;  
            if (!Regex.IsMatch(textbox.Text, "^\\d*\\.?\\d*$") && textbox.Text != "")  
            {  
                int txtPos = textbox.SelectionStart - 1;  
                textbox.Text = textbox.Text.Remove(txtPos, 1);  
                textbox.SelectionStart = txtPos;  
            }       
        }  
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2022-11-03T06:28:16.913+00:00

    Hello @VoyTec
    Welcome to Microsoft Q&A!

    1. I want to make a pop-up window with yes/no option, and then use the selection into a code.

    It is recommended to use MessageDialog Class, which can achieve your needs.

    Page.xaml

        <Button Content="Button" Margin="694,478,0,0" VerticalAlignment="Top" Click="Button_Click" Height="104" Width="170"/>  
        <TextBlock x:Name="tb"  Margin="203,182,203,649" FontSize="20"/>  
    

    Page.xaml.cs

       private void Button_Click(object sender, RoutedEventArgs e)  
        {  
            this.tb.Text = "";       
            ShowMessageDialog();  
               
        }  
    
        private async void ShowMessageDialog()  
        {  
            var msgDialog = new Windows.UI.Popups.MessageDialog("I am a reminder") { Title = "Tip title" };  
            msgDialog.Commands.Add(new Windows.UI.Popups.UICommand("OK", uiCommand => { this.tb.Text = $"You click:{uiCommand.Label}"; }));  
            msgDialog.Commands.Add(new Windows.UI.Popups.UICommand("Cancel", uiCommand => { this.tb.Text = $"You click:{uiCommand.Label}"; }));  
            await msgDialog.ShowAsync();  
        }  
    
    1. And the problem is that this NuGet isn't perfect, in a matter of fact it is really bugged. Is there, a way to find a perfect working box with values only, for calculations?

    Are you using the NumberBox of WInUI? What specific problems did you encounter during use?

    Thank you.
    Junjie


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.