WPF - Button to create New root object

WPF - Button to create New root object

Old forum URL: forums.lhotka.net/forums/t/7691.aspx


ritchied posted on Monday, September 28, 2009

I learning CSLA.NET, C# and WPF all at the same time, so what is obvious to others is a challenge to me.Smile [:)]

In my little learning app, I have a TextBox to enter the id of an existing object.  I have a button that I want to create the object with the id passed as a parm.

I was successful in binding the TextBox with the PopertyChanged for UpdateSourceTrigger.  This creates the object passing the id with the first change and then keeps the object up to-date.  Great.

Now, how to create a New root object with the command button passing the id from a text box.

Thanks, Duncan

RockfordLhotka replied on Monday, September 28, 2009

I'm not aware of a XAML-only solution to this problem.

You can use commanding - so the button triggers a command. But you still need to write code to handle the command, and the default place for that code is in the form's code-behind. At which point I'm left wondering why you wouldn't just handle the Click event, since that requires less code and effort...

Or you can explore the MVVM pattern and associated frameworks. This means taking on some complexity upfront to get the pattern online in your app. But in the longer term it is probably worth it, because you shift the "click handler" out of code-behind and into a separate UI class. It is the same code, but being in a separate class it is more testable and therefore (hopefully) more maintainable.

ritchied replied on Tuesday, September 29, 2009

Thank you.

I will go with the clicked event.

 

Duncan.

Copyright (c) Marimer LLC