Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Databinding question
2 replies. Latest Post by PeterMorris on August 24, 2008.
(0)
PeterMorris
Member
2 points
18 Posts
08-23-2008 11:16 AM |
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
Star
14606 points
2,730 Posts
08-24-2008 2:59 AM |
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
08-24-2008 4:50 AM |
Unfortunate that this is the case, but useful to know. Thanks very much!