Programming question

So I’m starting to work with UWP apps, and I’m continuing to build my C# skills as I go but I’m hitting a wall here. I want to take input from two textboxes, and when a button is selected, provide the output.

The bog-standard C# would be…

static void Main(string[] args)

       {

           Console.WriteLine(“Input 1”);

           string input1;

           input1 = Console.ReadLine();

           Console.WriteLine(“Input 2”);

           string input2;

           input2 = Console.ReadLine();

           Console.WriteLine(input1 + ” ” + input2);

           Console.ReadLine();

       }

I’m not sure what the best way to display the result in a UWP app would be. I originally thought that a message box would be right, but… Between trying to find documention on UWP message boxes, and just thinking more about it, I want it to appear in the window, and I’d like to use a TextBlock so that it simply appears, no border. But there’s scant little documenation on that as well.

So… how does one write to a UWP TextBlock?

Conversation 11 comments

  • Jules Wombat

    14 May, 2017 - 10:06 am

    <p>Depends how you want your output displayed. If you don't want/ expect any editing of the output, why not use TextBlock (Textblock.Text = OutputString) Then style the TextBlock how you want in XAML. </p><p><br></p>

    • jimchamplin

      Premium Member
      14 May, 2017 - 11:05 am

      <blockquote><a href="#116688"><em>In reply to Jules Wombat:</em></a></blockquote><p>Can OutputString be set to a string variable that updates when the var changes? If so that would be perfect. I'm going to go try it now!</p>

    • jimchamplin

      Premium Member
      14 May, 2017 - 11:27 am

      <blockquote><a href="#116688"><em>In reply to Jules Wombat:</em></a></blockquote><p><em>VICTORY! :D</em></p>

    • jimchamplin

      Premium Member
      14 May, 2017 - 11:41 am

      <blockquote><a href="#116688"><em>In reply to Jules Wombat:</em></a></blockquote><p>I have two textBoxen, myFirstName and myLastName (thanks for those variable names, Bob Tabor,) a TextBlock called nameOutput, and a button, sayHello. When sayHello is invoked…</p><p><br></p><p> string myFullName;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myFullName = myFirstName.Text + " " + myLastName.Text;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nameOutput.Text = "Hello, " + myFullName;</p><p><br></p><p>And boom.</p><p><img src="http://orig04.deviantart.net/fb26/f/2017/134/9/3/screenshot__1__by_thejimmyjames-db96uu1.png"></p&gt;

      • Jules Wombat

        14 May, 2017 - 4:27 pm

        <blockquote><a href="#116704"><em>In reply to jimchamplin:</em></a></blockquote><p>Great. That is how I run most of my basic Applications.</p><p>You will need to study 'bindings', if you want more advance means of the display control updating when the data changes. Binding User Control to Data is the advised way to manage more complex displays, as it avoids having to explicitly invoke TextBlick.Text = OutString.</p><p>But to be honest I haven't got my head around all the different binding complexities. So just use the above basic explicit method.</p>

        • jimchamplin

          Premium Member
          14 May, 2017 - 5:53 pm

          <blockquote><a href="#116744"><em>In reply to Jules Wombat:</em></a></blockquote><p>Yeah, I'm still pretty early on in this. I literally created my first UWP project in VS yesterday. Truth is that I'm wanting to push into this early, before I've even really mastered C#, because I'm trying to convince a family member to shell out for me to take formal programming courses. They're non-techie and showing them something on the console won't convince them as well as something they recognize as software.</p><p>Yeah… </p>

  • jimchamplin

    Premium Member
    14 May, 2017 - 11:10 am

    <blockquote><a href="#116645"><em>In reply to skane2600:</em></a></blockquote><p>Yeah, that's just some .NET stuff. Wanted to express the concept in the simplest way possible. :D</p><p>And yeaaaah, I've thought about joining stackoverflow, but it's that RTFM bent that you mention that I've seen in so many threads. Always makes me wonder what the point of the site is, if everyone's answer to the question is essentially, "Just go figure it out."</p>

    • skane2600

      14 May, 2017 - 11:46 am

      <blockquote><a href="#116702"><em>In reply to jimchamplin:</em></a></blockquote><p>Sometimes you get good answers, but there are those who try to convince you that you don't really want to do what you want to do, or are fixated on whether your question is appropriate given the site's arcane rules. The irony is that people often provide some of the most useful answers to questions other people have labeled as inappropriate. Then you have to earn some minimum reputation before you can answer a question. I guess some people really get excited over reputation and badges, but I find it rather juvenile.</p>

      • jimchamplin

        Premium Member
        14 May, 2017 - 12:00 pm

        <blockquote><a href="#116705"><em>In reply to skane2600:</em></a></blockquote><p>The rules business sounds like a bit of a turnoff honestly lol</p><p>I easily chafe at seemingly useless online bureaucracy and would probably piss them off…</p><p><br></p><p>…</p><p><br></p><p>…</p><p><br></p><p>… especially with how pitiful my code is and how profane my comments and variable names are. :D</p>

        • skane2600

          14 May, 2017 - 4:14 pm

          <blockquote><a href="#116706"><em>In reply to jimchamplin:</em></a></blockquote><p>Don't be too hard on your code. IMO the dev community has become too fixated on "best practices" sometimes to the detriment of code that satisfies its requirements with a minimum of bugs delivered in a reasonable amount of time.</p>

          • jimchamplin

            Premium Member
            14 May, 2017 - 5:55 pm

            <blockquote><a href="#116742"><em>In reply to skane2600:</em></a></blockquote><p>Yeah, I've seen that. One thread I looked at earlier today on UWP backgrounds, no actual discussion was made on the topic for all the people who complained about the OP's unusual formatting choices.</p>

Newsletter

Stay up to date with the latest tech news from Thurrott.com!

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Thurrott © 2023 BWW Media Group