This is a migrated thread and some comments may be shown as answers.

Cannot change DataField.Header from code

1 Answer 36 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ismael
Top achievements
Rank 1
Ismael asked on 30 Jan 2015, 10:59 AM
I'm trying to dynamically update the Header of a DataField from code, but the UI won't update (other properties like Visibility do update the UI, though).

Here's a simplified version of my code so far:

<telerikInput:RadDataForm x:Name="radDataForm" DataFieldValueChanged="RadDataForm_OnDataFieldValueChanged">
    <telerikInput:DataField TargetProperty="Url" Header="Url (or IP)" />
</telerikInput:RadDataForm>

private void RadDataForm_OnDataFieldValueChanged(object sender, DataFieldValueChangedEventArgs e)
{
    var dataForm = sender as RadDataForm;
    if (dataForm == null)
    {
        return;
    }
 
    var urlField = dataForm.FindFieldByPropertyName("Url").AssociatedDataField;
    if (urlField != null)
    {
        // NOTE: this won't update the UI
        urlField.Header = "IP (or Host) *";
 
        //// NOTE: this one DOES update the UI
        //urlField.Visibility = Visibility.Collapsed;
    }
}

Also, I've notice there is DataFile and DataFormField object: one has a Header and the other a LabelContent. Is there a way to work directly with the DataFormField in XAML?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Vladislav
Telerik team
answered on 03 Feb 2015, 09:27 AM
Hi Ismael,

It turns out that it is not possible to change directly the "Header" property of the DataField object.
As a workaround you can change the LabelContent property of the DataFormField property, like this:
var urlField = dataForm.FindFieldByPropertyName("Url");
if (urlField != null)
{
    urlField.LabelContent = "IP (or Host) *";
}

On your second question - since DataFormField is an object maintained internally by the RadDataForm it is not possible to work directly with it in XAML.

Please note that we have discontinued the support for the WindowsPhone7 and we highly recommend to use our latest release of RadControls for WindowsPhone8.

Regards,
Vladislav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
DataForm
Asked by
Ismael
Top achievements
Rank 1
Answers by
Vladislav
Telerik team
Share this question
or