Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
Exception assigning style in CellControlAttached
posted

I am new to Silverlight, so I might be missing something.

I just upgraded to NetAdvantage 2010 Vol 1 from 2009 Vol 2. I did not have this issue with the previous version. I am using the XamWebGrid and following the example on conditional formatting on the Silverlight Samples site. In my “CellControlAttached” method I am doing this:

“e.Cell.Style = Application.Current.Resources["GridRed"] as Style;”.

When I do this, I get an exception.

[System.ArgumentException] = {System.ArgumentException: Value does not fall within the expected range.
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, DependencyObject doh)
   at System.Windows.DependencyObject.SetValue(DependencyProperty property, DependencyObject doh)
   at System.Windows.FrameworkElement.set_Style(Style value)
   at Infragistics.Silverlight.Controls.CellBase.ApplyStyle()
   at Infragistics.Silverlight.Controls.CellBase.set_Style(Style value)
   at NxServer.Views.Patient.dataGrid_CellControlAttached(Object sender, CellControlAttachedEventArgs e)

Even though I get the exception, the style is applied. What am I doing wrong?

  • 40030
    Suggested Answer
    Offline posted

    Hi Jim, 

    In 10.1 and in the next SR of 9.1 and 9.2, we made significant changes in terms of improving performance.  

    This changed effected how we're binding content to a cell.  Unfortunately, it had a side effect with when this event is called versus when the style is being applied.  Basically, there is a timing issue in SL 3, when you change a control template during a binding.  

    We didn't find this issue until right before release, and we didn't want to destabilize the control with a last minute fix.  However, there is a very simple workaround that should fix this for you:

    e.Cell.Control.Dispatcher.BeginInvoke(() =>

                {

                    e.Cell.Style = this.Resources["Style2"] as Style;

                });

     Basically, by delaying the update of the cell style slightly, it ensures the binding is complete and the control template can be updated safely. 

    Hope this helps, 

    -SteveZ