Skip to main content

Microsoft Silverlight

Answered Question How do I tell the field label for a DataFormTemplateField what I'm binding to?RSS Feed

(0)

StefanOlson
StefanOlson

Member

Member

244 points

113 Posts

How do I tell the field label for a DataFormTemplateField what I'm binding to?

If I have the following code:

<Controls:DataFormTemplateField>

<Controls:DataFormTemplateField.EditTemplate>

<DataTemplate>

<StackPanel Orientation="Horizontal">

<TextBlock Text="$"/>

<TextBox Text="{Binding Path=Bond}" Width="75"/>

</StackPanel>

</DataTemplate>

</Controls:DataFormTemplateField.EditTemplate>

</Controls:DataFormTemplateField>

The data form doesn't automatically pick up the binding and display the field label and bold it appropriately, presumably because it doesn't know that I'm binding to the bond property.  How can I tell it this so that it will correctly bold the field label and pull the text for the label out of the bond property?

 ....Stefan

http://www.olsonsoft.com/blogs/stefanolson

SLMonster
SLMonster

Member

Member

299 points

65 Posts

Re: How do I tell the field label for a DataFormTemplateField what I'm binding to?

you may need to set DataContext to the Dataform

StefanOlson
StefanOlson

Member

Member

244 points

113 Posts

Re: How do I tell the field label for a DataFormTemplateField what I'm binding to?

SLMonster:

you may need to set DataContext to the Dataform

The current item is set correctly, that is not the problem. It is with the design of the field, there's no way to tell what you're binding to.

...Stefan

http://www.olsonsoft.com/blogs/stefanolson

Jonathan Shen – MSFT
Jonathan...

All-Star

All-Star

24979 points

2,434 Posts

Microsoft

Re: How do I tell the field label for a DataFormTemplateField what I'm binding to?

Hi Stefan,

For example,

<df:DataForm.Fields> 
        <df:DataFormTextField IsReadOnly="True" Binding="{Binding MovieID}" FieldLabelContent="ID" /> 
        
        <df:DataFormTextField Binding="{Binding Name }" FieldLabelContent="Name" /> 
        
        <df:DataFormTemplateField FieldLabelContent="Year"
          <df:DataFormTemplateField.DisplayTemplate> 
            <DataTemplate> 
              <TextBox Text="{Binding Year}" HorizontalAlignment="Left" /> 
            </DataTemplate> 
          </df:DataFormTemplateField.DisplayTemplate> 
          <df:DataFormTemplateField.EditTemplate> 
            <DataTemplate> 
              <controls:NumericUpDown Maximum="2050" Minimum="1900" IsEditable="False" 
alue="{Binding Year, Mode=TwoWay, Converter={StaticResource yearConverter}}" HorizontalAlignment="Left" /> 
            </DataTemplate> 
          </df:DataFormTemplateField.EditTemplate> 
        </df:DataFormTemplateField> 
        
        <df:DataFormDateField Binding="{Binding AddedOn}" IsReadOnly="True" FieldLabelContent="Date Added" /> 
        
        <df:DataFormTextField Binding="{Binding Producer}" FieldLabelContent="Producer" /> 
        
        <df:DataFormComboBoxField Binding="{Binding Genre, Mode=TwoWay, Converter={StaticResource enumSelectedValueConverter}}" FieldLabelContent="Genre" /> 
</df:DataForm.Fields> 

Please make sure that your DataContext or ItemsSource is ok.  You can get a working sample here.

Best regards,

Jonathan

 

Jonathan Shen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

StefanOlson
StefanOlson

Member

Member

244 points

113 Posts

Re: How do I tell the field label for a DataFormTemplateField what I'm binding to?

Jonathan,

That does not address my question. The problem is that the field label does not pick up the validation properties of the property that I'm binding to and therefore bold the field label. In the example you have posted off that site none of the items are bold because validation properties not being used.

 ...Stefan

http://www.olsonsoft.com/blogs/stefanolson

Jonathan Shen – MSFT
Jonathan...

All-Star

All-Star

24979 points

2,434 Posts

Microsoft

Re: How do I tell the field label for a DataFormTemplateField what I'm binding to?

Hi Stefan,

StefanOlson:
The problem is that the field label does not pick up the validation properties of the property that I'm binding to and therefore bold the field label.

Not quite sure about what you want.  

StefanOlson:
In the example you have posted off that site none of the items are bold because validation properties not being used.

Please take a look at this video tutorial.   It shows you how to use validation on DataForm. For the ValidateProperty, please take  a look at this article.

Best regards,

Jonathan

Jonathan Shen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

StefanOlson
StefanOlson

Member

Member

244 points

113 Posts

Re: How do I tell the field label for a DataFormTemplateField what I'm binding to?

Jonathan Shen – MSFT:

Not quite sure about what you want.  

if a property has the required attribute, e.g:

[DataMember()]

[Required()]

public decimal Bond

then the field label is automatically made bold, when you use one of the built-in field types. If you try and use a template field, as I have shown an example of above, the field label is not automatically made bold, because the field label does not know which property you are binding to.

There needs to be a way to tell the field label which property you are binding to so that can appropriately figure out if the attribute is required and bold itself.

 ...Stefan

 

http://www.olsonsoft.com/blogs/stefanolson

Jonathan Shen – MSFT
Jonathan...

All-Star

All-Star

24979 points

2,434 Posts

Microsoft

Re: How do I tell the field label for a DataFormTemplateField what I'm binding to?

Hi Stefan,

I have upgraded my Silverlight Tools to a internal version.  Seems DataForm stops working now. Since Silverlight 3 will be released very soon, would you please upgrade it and have a test.  If it doesn't work, please open a new thread and share the link with me.  Thanks for you understanding.

Best regards,

Jonathan

Jonathan Shen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

StefanOlson
StefanOlson

Member

Member

244 points

113 Posts

Re: How do I tell the field label for a DataFormTemplateField what I'm binding to?

Jonathan,

I'm not quite sure what you would like me to upgrade to, I'm not aware of a later version of Silverlight 3 or the Silverlight 3 tools I can test with.  Can you let me know the URL where I can download the latest version? Currently running Silverlight 3.0.4037.0.  In Visual Studio (i.e Silverlight 3 tools):

Microsoft Silverlight Projects 2008
Version 9.0.30729.4063

Personally, I am very concerned that Silverlight 3 will be released without a release candidate, because there are a number of issues that I am not sure if they've been fixed in the final Silverlight release, and I'm also concerned that additional problems could be introduced.

...Stefan

http://www.olsonsoft.com/blogs/stefanolson

Jonathan Shen – MSFT
Jonathan...

All-Star

All-Star

24979 points

2,434 Posts

Microsoft

Re: How do I tell the field label for a DataFormTemplateField what I'm binding to?

Hi Stenfan,

Silverlight 3 RTW has not been released yet.  Anyway, it will be released very soon.

Best regards,

Jonathan

Jonathan Shen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

StefanOlson
StefanOlson

Member

Member

244 points

113 Posts

Answered Question

Re: How do I tell the field label for a DataFormTemplateField what I'm binding to?

In the Silverlight 3 RTW the new data field class has a PropertyPath member.  This can be set to tell the data field which property you are working with e.g.

<dataform:DataField PropertyPath="Bond">
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="$" VerticalAlignment="Center"/>
        <TextBox Text="{Binding Path=Bond}" Width="75"/>
    </StackPanel>
</dataform:DataField>

 ...Stefan

http://www.olsonsoft.com/blogs/stefanolson
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities