Skip to main content

Microsoft Silverlight

Answered Question Databinding questionRSS Feed

(0)

PeterMorris
PeterMorris

Member

Member

2 points

18 Posts

Databinding question

I have created a silverlight control and within it I have...

<TextBlock Text="{Binding Mode=OneWay, Path=Title}"

Within my application I have the following code...

        private void CreateAppMenus(ResponseData responseData)
        {
            var signalGroups =
                from signal in responseData.Signals
                where signal.DisplayPath.StartsWith("AppMenu")
                orderby signal.DisplayPath
                group signal by signal.DisplayPath into signalGroup
                select new
                    {
                        Title = signalGroup.Key.Split('/')[2],
                        Signals = new List<SignalInfo>(from signal in responseData.Signals where signal.DisplayPath == signalGroup.Key select signal)
                    };

            foreach (var signalGroup in signalGroups)
            {
                MenuBox menuBox = new MenuBox();
                StackPanelAppMenu.Children.Add(menuBox);
                menuBox.DataContext = signalGroup;
            }
        }

 As soon as the DataContext is set I get the following exception.  Can anyone tell me what is causing this and what to do about it?

 

Thanks

Pete

 

System.MethodAccessException was unhandled by user code
  Message="<>f__AnonymousType0`2.get_Title()"
  StackTrace:
       at System.Reflection.MethodBase.PerformSecurityCheck(Object obj, RuntimeMethodHandle method, IntPtr parent, UInt32 invocationFlags)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
       at System.Windows.Data.BindingExpression.ConnectToSource(Int32 index)
       at System.Windows.Data.BindingExpression.DataContextChanged(Object o, DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyProperty dp)
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean isSetByStyle, Boolean isSetByBuiltInStyle)
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at System.Windows.FrameworkElement.set_DataContext(Object value)
       at SilverOnion.Page.CreateAppMenus(ResponseData responseData)
       at SilverOnion.Page.CreateSignalsUI(ResponseData responseData)
       at SilverOnion.Page.RenderView(ResponseData responseData)
       at SilverOnion.Page.Client_StartSessionCompleted(Object sender, StartSessionCompletedEventArgs e)
       at SilverOnion.AppServer.ApplicationServiceClient.OnStartSessionCompleted(Object state)
  InnerException:
 

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP
Answered Question

Re: Databinding question

 Hello,

You shouldn't use Anonymous Types in Silverlight.

Please read #1 from http://michaelsync.net/2008/04/01/silverlight-2-beta1-known-issues-and-workarounds-if-any
 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


PeterMorris
PeterMorris

Member

Member

2 points

18 Posts

Re: Databinding question

Unfortunate that this is the case, but useful to know.  Thanks very much! 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities