SilverlightShow: A simplified DataForm replacement - Part 2 Adding validation support Comments http://www.silverlightshow.net/ Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples SilverlightShow.net http://www.rssboard.org/rss-specification Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic en-US estoychev@completit.com (Emil Stoychev) Validation on Cancel <p>Hello Andrea,</p> <p>I observed a small problem when canceling the form, the validation still occurs, I guess because</p> <p><span style="font-family: consolas; font-size: 13px; color: #0000ff;">if</span><span style="font-family: consolas; font-size: 13px;"> (!</span><span style="font-family: consolas; font-size: 13px; color: #0000ff;">this</span><span style="font-family: consolas; font-size: 13px;">.ValidateItem())<br /> </span><span style="font-family: consolas; font-size: 13px; color: #0000ff;">return</span><span style="font-family: consolas; font-size: 13px;">;</span></p> <p><span style="font-family: consolas; font-size: 13px; color: #0000ff;">if</span><span style="font-family: consolas; font-size: 13px;"> (</span><span style="font-family: consolas; font-size: 13px; color: #0000ff;">string</span><span style="font-family: consolas; font-size: 13px;">.Compare(commandName, </span><span style="font-family: consolas; font-size: 13px; color: #2b91af;">Form</span><span style="font-family: consolas; font-size: 13px;">.CommitCommand, </span><span style="font-family: consolas; font-size: 13px; color: #2b91af;">StringComparison</span><span style="font-family: consolas; font-size: 13px;">.OrdinalIgnoreCase) == 0){<br /> </span><span style="font-family: consolas; font-size: 13px; color: #0000ff;">   this</span><span style="font-family: consolas; font-size: 13px;">.OnCommit();<br /> </span><span style="font-family: consolas; font-size: 13px;">}<br /> </span><span style="font-family: consolas; font-size: 13px; color: #0000ff;">else</span><span style="font-family: consolas; font-size: 13px;"> </span><span style="font-family: consolas; font-size: 13px; color: #0000ff;">if</span><span style="font-family: consolas; font-size: 13px;"> (</span><span style="font-family: consolas; font-size: 13px; color: #0000ff;">string</span><span style="font-family: consolas; font-size: 13px;">.Compare(commandName, </span><span style="font-family: consolas; font-size: 13px; color: #2b91af;">Form</span><span style="font-family: consolas; font-size: 13px;">.CancelCommand, </span><span style="font-family: consolas; font-size: 13px; color: #2b91af;">StringComparison</span><span style="font-family: consolas; font-size: 13px;">.OrdinalIgnoreCase) == 0)<br />    </span><span style="font-family: consolas; font-size: 13px; color: #0000ff;">this</span><span style="font-family: consolas; font-size: 13px;">.OnCancel();</span></p> <p><span style="font-family: consolas; font-size: 13px;">I think the validation part shall be put only inside the Commit if, just before the this.OnCommit.</span></p> <p><span style="font-family: consolas; font-size: 13px;">right?</span></p> http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx#comment5271 wizardnet http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx Sat, 08 Jan 2011 16:28:36 GMT RE: A simplified DataForm replacement - Part 2 Adding validation support <p>I also noticed the behavior you describe but I didn't have the time to investigate the issue. I figure out the DataForm scans the fields after the are rendered and make the alignment someway.</p> <p>Thanks for your message.</p> http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx#comment4398 Andrea Boschin http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx Fri, 03 Sep 2010 18:00:21 GMT RE: A simplified DataForm replacement - Part 2 Adding validation support <p>Great article. </p> <p>But the standard DataForm controls align the label and the textbox in a nice way (labels has got all the same width), whereas your solution it looks a bit flattered. </p> <p>I've no idea, how I could solve this. "SharedSizeGroup" seems not to be possible in silverlight.</p> <p>Thanks </p> <p>Peter </p> http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx#comment4396 PeterUstinof http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx Fri, 03 Sep 2010 17:38:59 GMT RE: A simplified DataForm replacement - Part 2 Adding validation support I had this exact problem and solved it in a much simpler and less complex way. First, the dataform is just fine however it does need a little push in the MVVM drection. I solved mine with a behavior that exposes two things. A ValidateAndCommit command and a EditComplete event. Simply tell any control to call the command on the the behavior and wire any event handler you want to the EditComplete event on the behavior and your done. What are the advantages? You don't need a custom control so all your themes will still work. Any control can call the command as it normally would. It can be dragged on your dataform in blend and wired up. Your still using the dataform and should it even support these things like it should have you can throw away the behavior and keep rockin... http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx#comment4065 razor http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx Tue, 27 Jul 2010 05:30:58 GMT RE: A simplified DataForm replacement - Part 2 Adding validation support thank you all for the feedbacks. It's good to know my work is useful. bye. http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx#comment3549 Andrea Boschin http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx Fri, 07 May 2010 16:55:12 GMT RE: A simplified DataForm replacement - Part 2 Adding validation support Thank you Semkaa for the help.  The build action had to be set to Resource.  Problem solved!  Thanks again to Andrea for a great article.  This will be a great addition to our project. http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx#comment3548 mbrig http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx Fri, 07 May 2010 16:50:43 GMT RE: A simplified DataForm replacement - Part 2 Adding validation support i agree, great article.  i am having the same problem though.  gettemplatechild returns null.  if the problem is in generic.xaml.  how can this be solved? http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx#comment3544 mbrig http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx Thu, 06 May 2010 16:39:56 GMT RE: A simplified DataForm replacement - Part 2 Adding validation support Good to know you have solved you issue. Thanks. http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx#comment3185 Andrea Boschin http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx Sun, 07 Mar 2010 10:19:22 GMT RE: A simplified DataForm replacement - Part 2 Adding validation support Fixed that, it was all about generic.xaml. <div>Andrea, thanks again for great job.<br /> </div> http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx#comment3184 Semkaa http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx Sun, 07 Mar 2010 03:40:36 GMT RE: A simplified DataForm replacement - Part 2 Adding validation support <div style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; background-image: none; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-align: left; word-wrap: break-word; ">Great article. Thanks. This is exactly what I need. <div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">But I can't embed this control into my project.</div> <div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">I made a page like yours MainPage.xaml, but in OnApplyTemplate() method GetTemplateChild() returns null, which makes impossible further control initialization.<br /> </div> </div> http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx#comment3183 Semkaa http://www.silverlightshow.net/items/A-simplified-DataForm-replacement-Part-2-Adding-validation-support.aspx Sun, 07 Mar 2010 03:08:57 GMT