Potential System.InvalidOperationException in DataFormDataField.SetLabelStyle()

2 posts, 0 answers
  1. Rashad Rivera
    Rashad Rivera avatar
    63 posts
    Member since:
    Aug 2009

    Posted 09 May 2012 Link to this post

    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
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 14 May 2012 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top