WPF C# How can I get data from a datepicker and put it into a textbox?

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 1347 Views - Last Post: 24 April 2016 - 06:14 PM Rate Topic: -----

#1 Yehmum   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-April 16

WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 23 April 2016 - 01:45 PM

In this screenshot Screenshot - Imgur I have used a datepicker, timepicker and textbox. How can I transfer all that data into a textbox? Would a binding source work? How would I use that?
Is This A Good Question/Topic? 0
  • +

Replies To: WPF C# How can I get data from a datepicker and put it into a textbox?

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 23 April 2016 - 02:13 PM

Please see my signature block. There are several tutorials for WPF linked.

I might suggest reading and learning about how you should code in WPF *before* you just drag-n-drop all willy-nilly with no idea of what to do next.
Was This Post Helpful? 1
  • +
  • -

#3 Yehmum   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-April 16

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 23 April 2016 - 02:22 PM

Quote

*before* you just drag-n-drop all willy-nilly with no idea of what to do next.


I know what I want to do, I just don't know how to achieve it. Anyways, thanks for the links, I will check them out.

Also, do you have a link specifically on the topic I want so I don't just have to click on all of them and search through?
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 23 April 2016 - 02:28 PM

I just looked at the code shown in that capture.
Stop. Just stop.

You REALLY need to stop trying to code anything. Its clear looking at that code that you really did just drag-n-drop of the toolbox. I was joking until I saw it in the code. And for some odd reason the controls all have names.

Just back away from the keyboard right now. You need to go get a book on WPF and read it. At least the first few chapters that describe the basic foundation concepts. Software development is not something you just decide one day to dick around with and pick up on your own without reading a darned thing by what you can figure out by randomly clicking and dragging.

You can't target what you need to read to just "how do I get data into a datepicker, timepicker and textbox". It just doesn't work that way. Its like saying "How do I drive on a dirt road just enough to get from my house to the grocery store?" with no idea of how to drive or what the road rules are.

This post has been edited by tlhIn`toq: 23 April 2016 - 02:30 PM

Was This Post Helpful? 0
  • +
  • -

#5 Yehmum   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-April 16

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 23 April 2016 - 02:41 PM

What is the huge issue with the toolbox? That's what it's there for. To use things from. Why would I spend my time typing out everything when I can get it straight from the toolbox? Also: I was able to figure everything else out like getting buttons to take you to a certain page in the app. I'm not really seeing the huge issue here.

Quote

You can't target what you need to read to just "how do I get data into a datepicker, timepicker and textbox". It just doesn't work that way.

When you say it doesn't work this way, this link is similar to what I want to do: Get the user input from a text box and store it. http://stackoverflow...wpf-application
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,229
  • Joined: 12-December 12

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 23 April 2016 - 03:04 PM

It is the second answer at that SO link that provides a better picture of how WPF works.

Besides, the question is about storing a value in a variable, not linking between controls, which can be done (almost) entirely in XAML. (To get both the date and time you probably need a converter to construct a string.)
Was This Post Helpful? 0
  • +
  • -

#7 Yehmum   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-April 16

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 23 April 2016 - 03:10 PM

View Postandrewsw, on 23 April 2016 - 03:04 PM, said:

It is the second answer at that SO link that provides a better picture of how WPF works.

Besides, the question is about storing a value in a variable, not linking between controls, which can be done (almost) entirely in XAML. (To get both the date and time you probably need a converter to construct a string.)


Thank you for a helpful answer :D
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,229
  • Joined: 12-December 12

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 23 April 2016 - 03:17 PM

MultiBinding (WPF)
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,977
  • Joined: 05-May 12

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 23 April 2016 - 08:11 PM

View PostYehmum, on 23 April 2016 - 05:41 PM, said:

What is the huge issue with the toolbox? That's what it's there for. To use things from. Why would I spend my time typing out everything when I can get it straight from the toolbox?

Nothing wrong with the toolbox, but the point he is trying to make is that you should be making a concerted effort to learn why you are picking things from the toolbox. The toolbox is just there to make things easier to do. It won't do the thinking for you. Let me put it this way:
Autocad has a ton of options in its tool palette, but that doesn't mean that you can automatically design a Boeing 777.
When you sit at a dentist chair, there is a whole array of instruments available to you, but that doesn't mean you are necessarily qualified to perform a root canal.

Also note that as you gain experience in programming, the UI is actually the among the last things you need to worry about unless your particular field of expertise is user experience design, and/or computer graphics. You first worry about how data flows through the system correctly and efficiently.
Was This Post Helpful? 0
  • +
  • -

#10 GetSet   User is offline

  • D.I.C Regular

Reputation: 44
  • View blog
  • Posts: 411
  • Joined: 08-February 11

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 23 April 2016 - 08:20 PM

The future of programming. "Why would I spend my time..."
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,229
  • Joined: 12-December 12

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 24 April 2016 - 02:00 AM

My purpose in referring to the second answer at that SO link, and linking to my MuliBinding tutorial, is so that you would hopefully realise that there is a lot more to studying and understanding WPF than simply fumbling around in Visual Studio, looking to find the easiest solution (fudge) to each individual question as it occurs to you. Understanding WPF, that is, to do anything non-trivial with it, requires structured learning, with a book or detailed tutorials. Your current approach is destined to failure and frustration.
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,229
  • Joined: 12-December 12

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 24 April 2016 - 02:32 AM

Actually, I've just noticed that you aren't using a DatePicker, nor some (custom) TimePicker, so you have even more work to do, to do something useful with the values entered in your input boxes.
Was This Post Helpful? 0
  • +
  • -

#13 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,977
  • Joined: 05-May 12

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 24 April 2016 - 05:19 AM

So our OP could not even pick the right tools out of the toolbox... Even more reason to step back from the current program and learn properly.
Was This Post Helpful? 1
  • +
  • -

#14 Yehmum   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-April 16

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 24 April 2016 - 06:30 AM

View PostGetSet, on 23 April 2016 - 08:20 PM, said:

The future of programming. "Why would I spend my time..."

I'm not saying that about programming in general, and I'm not saying that I'm lazy. I said that because you can get for example a rectangle by using the toolbox or my typing out the coding for a rectangle. I'm saying that 1 way is faster, easier and more efficient than the other, so there is no point in doing it the other way when you have that way.

View PostSkydiver, on 24 April 2016 - 05:19 AM, said:

So our OP could not even pick the right tools out of the toolbox... Even more reason to step back from the current program and learn properly.

If you think I didn't pick the right tool, what should I have picked for users to be able to enter text?
Was This Post Helpful? 0
  • +
  • -

#15 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: WPF C# How can I get data from a datepicker and put it into a textbox?

Posted 24 April 2016 - 08:05 AM

The toolbox itself if fine. I use it to store reusable text blocks in. But using it to drag and drop controls to your Window designer is HORRIBLE.

It has to guess how to lay out your controls so that they work for you. It has no idea of what your plans are or your intent for your design. So it falls back to thinking you want absolute positioning and accomplishes this for you by setting hard margins and sizes on every control. Look at the XAML markup and you'll see this.

Nobody does this in the real world. One of the key points of WPF is that controls will self-adjust to the space available. XAML that is hand coded is far smaller and at the same time less rigid than what is produced by drag-n-drop. Normally you would build a Window by nesting various pannels.

Put in a StackPanel with vertical orientation.
Add a few buttons or lables that display information all the time.
put in a Scrollview to hold the body of your window so it can scroll if you have more controls than fit on the screen.
put in a statusbar at the bottom to display... well... status information.

Tadaaa... You have a page with header & footer/status and a scrolling view in the middle. All with less than 20 lines of XAML. None of it drag-n-drop. None of it hard coded for size or position. It will all flow and expand to fit the screen whether its a Windows phone, tablet or 2560x2000 ultra-hi-res monitor.

Honestly... If your view of coding is "why should I bother doing any little bit more than I have to?"... You're in the wrong line of work. I sure hope this is not an example of your general work ethic and outlook, but frankly its sad. If you have this idea that making software is all drag-n-drop for a day then sell your software on line for a fast retirement you have no idea what development is.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2