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

Potential System.InvalidOperationException in DataFormDataField.SetLabelStyle()

1 Answer 25 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Rashad Rivera
Top achievements
Rank 1
Rashad Rivera asked on 09 May 2012, 10:39 PM
Hello,

Found a potential bug in the private DataFormDataField.SetLabelStyle() method.  Basically, a user of the DataForm control can cause an exception of their lable content is not the same type as that specified in the LabelStyle's TargetType.  As a fix, we can just check the types and apply if the are compatible.  Here is how to fix the bug:

1) In the 'Telerik.Windows.Controls.DataFormDataField' class, you will see the SetLabelStyle method defined as:
private void SetLabelStyle() {
    FrameworkElement label = this.GetTemplateChild("PART_Label") as FrameworkElement;
    if (label != null &&
        this.ParentForm != null &&
        this.ParentForm.LabelStyle != null) {
        label.Style = this.ParentForm.LabelStyle;
    }
}

Replace this method with:
private void SetLabelStyle() {
    FrameworkElement label = this.GetTemplateChild("PART_Label") as FrameworkElement;
    if (label != null &&
        this.ParentForm != null &&
        this.ParentForm.LabelStyle != null &&
        this.ParentForm.LabelStyle.TargetType.IsCompatibleWith(label.GetType())) {
        label.Style = this.ParentForm.LabelStyle;
    }
}

Please use this fix until Telerik gets around to correcting the bug.

- Rashad Rivera, Omegus Prime, LLC

1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 14 May 2012, 07:20 AM
Hi Rashad Rivera,

This seems to be quite a reasonable precaution. Thank you for attracting our attention to this potential issue. I have updated your Telerik points status accordingly. The change will be applied with our next official release version.

Greetings,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
DataForm
Asked by
Rashad Rivera
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question
or