Skip to main content
Home Forums Silverlight Programming WCF RIA Services Setting a default IValueConverter in DataForm
6 replies. Latest Post by matthunter on November 6, 2009.
(0)
matthunter
Member
0 points
11 Posts
11-06-2009 7:56 AM |
Hi Everyone,
Is there a way to set a default IValueConverter for binding in a DataForm?
I've got values that are nulls on [Editable(false)] fields that are being turned into strings, and failing validation when submited back to the server.
I've had a look in the forums, and before you could do it by using DataFormBoundField, however this has not been removed since July CTP.
I'd rather not rely on the devs adding a Converter to the binding in the xaml everytime they add a field (I already have an IValueConverter that does what I need).
Anyway, any help would be much appreciated.
Cheers
Matt.
bryant
Star
9937 points
1,629 Posts
11-06-2009 12:55 PM |
What if you put [ReadOnly(true)]
[
Instead of the editable?
11-06-2009 4:42 PM |
Hi,
Thanks for your response.
I tried ReadOnly[true], but it's a similar affect and fails when I try to commit the entity.
I had a glimmer of hope when i found you could set "[DisplayFormat(ConvertEmptyStringToNull = true)]", but this does not get carried accross from the server to the generated entity file in Silverlight - which I think is odd (bug?)
Any other ideas?
Matt
11-06-2009 5:15 PM |
If you're using ReadOnly then the property cannot be changed on the client, so there must be a seperate issue. Is the value coming from the server with an empty string in it?
11-06-2009 8:19 PM |
Nope, can confirm the field is coming back from server as null
Looks like this in web app:
1 [Display(Name = "[N/A]")][ReadOnly(true)][DataType(DataType.Text)][DisplayFormat(ConvertEmptyStringToNull = true)] 2 public string VersionNumber 3 { 4 get 5 { 6 return this.GetString("versionnumber"); 7 } 8 set 9 { 10 this.SetString("versionnumber", value); 11 } 12 }
Looks like this in silverlight:
1 [DataMember()] 2 [DataType(DataType.Text)] 3 [DisplayFormat()] 4 [Display(Name="[N/A]")] 5 [ReadOnly(true)] 6 public string VersionNumber 7 { 8 get 9 { 10 return this._versionNumber; 11 } 12 set 13 { 14 if ((this._versionNumber != value)) 15 { 16 this.ValidateProperty("VersionNumber", value); 17 this.OnVersionNumberChanging(value); 18 this.RaiseDataMemberChanging("VersionNumber"); 19 this._versionNumber = value; 20 this.RaiseDataMemberChanged("VersionNumber"); 21 this.OnVersionNumberChanged(); 22 } 23 } 24 } 25
Binding like this on DataForm:
<dataForm:DataField> <TextBox Text="{Binding VersionNumber, Mode=TwoWay}" /> </dataForm:DataField>
11-06-2009 8:22 PM |
Just use OneWay binding if you don't want it to change.
11-06-2009 8:23 PM |
Binding OneWay works (of course), however I would have thought it might be smarter than that :)
Nevermind, at least a little more obvious that having to put an IValueConverter on to take care of the null.