Unhandled exception thrown on binding to image collection

2 posts, 0 answers
  1. Larry
    Larry avatar
    1 posts
    Member since:
    Sep 2010

    Posted 26 Jan 2011 Link to this post

    <telerik:RadCoverFlow Width="700" Canvas.ZIndex="1200"  Grid.Row="1" Grid.ColumnSpan="2" OffsetY="60" OffsetX="0" Opacity="0" ItemsSource="{Binding}" x:Name="Cover" SelectionChanged="Cover_Change" DistanceBetweenItems="50" ReflectionOpacity="2" ReflectionHeight="0.25" RotationY="45" ItemScale=".75" VerticalAlignment="Stretch" HorizontalAlignment="Left" Margin="10,30,35,20">
                   <telerik:RadCoverFlow.Resources>
                       <Style TargetType="telerik:RadCoverFlowItem">
                           <Setter Property="telerik:RadDragAndDropManager.AllowDrag" Value="True"></Setter>
                       </Style>
                   </telerik:RadCoverFlow.Resources>
                   <telerik:RadCoverFlow.ItemTemplate>
                       <DataTemplate x:Name="cfDataTemplate">
                      
                           <ContentPresenter Content="{Binding ObtainedImage}"   HorizontalAlignment="Stretch" VerticalAlignment="Stretch" telerik:RadCoverFlow.EnableLoadNotification="True"></ContentPresenter>
                 
           
                       </DataTemplate>
                   </telerik:RadCoverFlow.ItemTemplate>
               </telerik:RadCoverFlow>
    Hi Iam binding to the above coverflow an observableCollection<slide> of this slide class:
    public class Slide
        {
            public Slide()
            {
     
              
            public string ImageName { get; set; }
     
            public BitmapImage ObtainedBitmap { get; set; }
     
            public Image ObtainedImage { get; set; }
         
        }

    The images are obtained as a stream using WCF services and then bitmap images and Image objects are created from them. Everytime I bind the collection to the coverflow datacontext I get the following unhandled exception:

    ExceptionObject {System.ArgumentException: Value does not fall within the expected range.
     
       at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
       at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
       at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
       at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
       at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
       at System.Windows.Data.BindingExpression.SendDataToTarget()
       at System.Windows.Data.BindingExpression.SourceAcquired()
       at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)
       at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnTreeParentUpdated(DependencyObject newParent, Boolean bIsNewParentAlive)
       at System.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent, IManagedPeer newParent, Boolean bIsNewParentAlive, Boolean keepReferenceToParent)
       at MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(IntPtr oldParentElement, IntPtr parentElement, IntPtr childElement, Byte bIsParentAlive, Byte bKeepReferenceToParent, Byte bCanCreateParent)}    System.Exception {System.ArgumentException}

    And one less image gets displayed in the coverflow. Basically if there are 10 images that are obtained using WCF services and put into the collection and then the collection is binded to the coverflow datacontext, it throws the above exception and 9 images gets displayed with blank space for one of the images.
  2. George
    Admin
    George avatar
    1332 posts

    Posted 31 Jan 2011 Link to this post

    Hello Larry,

     
    I would suggest you to use an Image control instead of ContentPresenter in the ItemTemplate of the RadCoverFlow control. It is not a good practice to use UIElement in your ViewModel. Then you could bind the Image.Source property to the ObtainedBitmap.

    I hope this suit your needs.

    Regards,
    George
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. DevCraft banner
Back to Top