开发者

Add new record with form in wpf

Yesterday I posted a question how I could validate a form WITHOUT the forms datacontext set to an object.

"It is the equivalent of monkeys ju开发者_如何学Pythonggling with grenades" I read in a comment.

Right. So. I want to get it straight how it works then. Lets say I have a simple form with two textboxes and a button to submit the data in the form. Let's say I am filling in stuff about a product. But how can I set the datacontext to something that doesn't exist yet? And how can I validate the textboxes for not being empty with that?


There's a 1000 ways to skin a cat

For Button & TextBoxes. You could bind the IsEnabled of the button to the Length of the Text.Length with a converter. This way the user wouldn't be able to save anything without typing something in.

For the DataContext: Do you really need one? Are you creating a UserControl that will be used elsewhere? Put everything in the codebehind if you need to. If you need a DataContext, create an empty one, it's a simple POCO object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜