Error setting RadContextMenu.ItemContainerStyle in SL4

3 posts, 1 answers
  1. Brandon Strevell
    Brandon Strevell avatar
    6 posts
    Member since:
    Aug 2009

    Posted 25 Mar 2010 Link to this post

    I'm getting a run-time error "Set property '' threw an exception" when I set the ItemContainerStyle of a RadContextMenu using the Silverlight 4 RC 2010.1 309.  Am I doing something wrong?

        <UserControl.Resources> 
            <local:DataItemCollection x:Key="ItemsSource"
                <local:DataItem Text="Item 1"
                    <local:DataItem Text="Item 1.1" /> 
                    <local:DataItem Text="Item 1.2" /> 
                    <local:DataItem Text="Item 1.3" /> 
                </local:DataItem> 
                <local:DataItem Text="Item 2"
                    <local:DataItem Text="Item 2.1" /> 
                    <local:DataItem Text="Item 2.2" /> 
                    <local:DataItem Text="Item 2.3" /> 
                </local:DataItem> 
                <local:DataItem Text="Item 3"
                    <local:DataItem Text="Item 3.1" /> 
                    <local:DataItem Text="Item 3.2" /> 
                    <local:DataItem Text="Item 3.3" /> 
                </local:DataItem> 
            </local:DataItemCollection> 
        </UserControl.Resources> 
        <Grid> 
            <telerikNavigation:RadContextMenu ItemsSource="{Binding Source={StaticResource ItemsSource}}" > 
                <telerikNavigation:RadContextMenu.ItemContainerStyle> 
                    <Style TargetType="telerikNavigation:RadMenuItem"
                        <Setter Property="Header" Value="{Binding Text}"/> 
                        <Setter Property="ItemsSource" Value="{Binding Children}"/> 
                    </Style> 
                </telerikNavigation:RadContextMenu.ItemContainerStyle> 
            </telerikNavigation:RadContextMenu> 
        </Grid> 

    System.Windows.Markup.XamlParseException occurred
      Message=Set property '' threw an exception. [Line: 35 Position: 53]
      LineNumber=35
      LinePosition=53
      StackTrace:
           at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
      InnerException: System.NotSupportedException
           Message=Cannot set read-only property ''.
           StackTrace:
                at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value)
                at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue)
           InnerException: 
  2. Answer
    Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 26 Mar 2010 Link to this post

    Hello Brandon Strevell,

    Silverlight 4 doesn't support Bindings in Style setter.
    <Setter Property="Header" Value="{Binding Text}"/>

    With the RC release the parser now throws exception (in SL 3 it was ignored).
    We have workaround for this - ContainerBindingCollection where you specify Binding for each property of the container (in this case RadMenuItem) that have to be bound.
    You can see an example with source code here:
    http://demos.telerik.com/silverlight/#Menu/DataBinding

    Let us know if you need more information.

    Kind regards,
    Hristo
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Brandon Strevell
    Brandon Strevell avatar
    6 posts
    Member since:
    Aug 2009

    Posted 26 Mar 2010 Link to this post

    Thank you, that makes perfect sense.
Back to Top