Skip to main content

Microsoft Silverlight

Answered Question Setting a default IValueConverter in DataFormRSS Feed

(0)

matthunter
matthunter

Member

Member

0 points

11 Posts

Setting a default IValueConverter in DataForm

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
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP

Re: Setting a default IValueConverter in DataForm

What if you put

[ReadOnly(true)]

Instead of the editable?

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

matthunter
matthunter

Member

Member

0 points

11 Posts

Re: Setting a default IValueConverter in DataForm

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?

Cheers

Matt

bryant
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP

Re: Re: Setting a default IValueConverter in DataForm

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?

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

matthunter
matthunter

Member

Member

0 points

11 Posts

Re: Re: Setting a default IValueConverter in DataForm

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>
 Perhaps because I've got binding two way?  Will check it out.

bryant
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP

Re: Re: Re: Setting a default IValueConverter in DataForm

Just use OneWay binding if you don't want it to change.

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

matthunter
matthunter

Member

Member

0 points

11 Posts

Answered Question

Re: Re: Setting a default IValueConverter in DataForm

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.

 

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities