Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

WPF Imaging Component Exception

Posted on 2009-05-13
8
Medium Priority
?
1,873 Views
Last Modified: 2013-12-17
Hi I am getting this exception , when I try to bind a listview with a List<MyImage> type

"No imaging component suitable to complete this operation was found."

occurs for the target ListView and Binding Expression Path = AllImages

Please see attached code

Please let me know how to fix this
<DataTemplate x:Key="BrowsePictureTemplate" DataType="{x:Type loc:MainContent}">
            <Grid Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.2*"/>
                    <RowDefinition/>    
                    <RowDefinition Height="0.3*"/>
                    <RowDefinition Height="0.2*"/>
                </Grid.RowDefinitions>
                <Image Grid.RowSpan="3" Grid.Row="0" Source="{Binding ElementName=ImageList,Path=SelectedItem.Image}">
 
                </Image>
                <ListView Grid.Row="2" ItemsSource="{Binding AllImages}" Name="ImageList" Background="Gray" Opacity="0.7" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" >
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"></StackPanel>
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Opacity="1">
                                <Image Source="{Binding Image}" Width="100" Height="100" Opacity="1"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
 
                <StackPanel Grid.Row="3" Background="Black">
 
                </StackPanel>
                <StackPanel Grid.Row="0" Background="Gray" Opacity="0.7" >
                    <TextBlock  Text="Awesome" />
                </StackPanel>
            </Grid>
        </DataTemplate>
 
 
////Code Behind C#///
 
public class MainContent
    {
  public List<MyImage> AllImages
        {
            get 
            {
                List<MyImage> result = new List<MyImage>();
                foreach (string filename in System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)))
                {
                    try
                    {
                        result.Add(new MyImage(new BitmapImage(new Uri(filename)), System.IO.Path.GetFileNameWithoutExtension(filename)));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
 
                }
                return result;
            }
           
        }
 
        /// <summary>
        /// Class for MyImage Type
        /// </summary>
 
        public class MyImage
        {
 
            public MyImage(ImageSource image, string name)
            {
                _image = image;
                _name = name;
            }
 
            public override string ToString()
            {
                return _name;
            }
            private ImageSource _image;
            public ImageSource Image { get { return _image; } }
 
            private string _name;
            public string Name { get { return _name; } }
 
        }
 
}

Open in new window

0
Comment
Question by:ctrlctrl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 24381083
try to use a ObservableCollection instead of list. say,
class YourImage:ObservableCollection<MyImage>
{
}
0
 

Author Comment

by:ctrlctrl
ID: 24386880
I used the below and it didnt work
      public ObservableCollection<MyImage> AllImages
        {
            get 
            {
                ObservableCollection<MyImage> result = new ObservableCollection<MyImage>();
               foreach (string filename in System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)))
               {
                   try
                   {
                       result.Add(new FlickrImage(new BitmapImage(new Uri(filename)), System.IO.Path.GetFileNameWithoutExtension(filename)));
                   }
                   catch (Exception ex)
                   {
                       throw new Exception(ex.Message);
                   }
 
               }
               return result;
 
            }
        }

Open in new window

0
 

Author Comment

by:ctrlctrl
ID: 24386895
sorry .. abt that.. .MyImage = FlickrImage , I was trying to keep the type name anonymous... Pleasse ignore
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 5

Expert Comment

by:rendaduiyan
ID: 24428366
you do not post all your XAML.
I suggest you removing Binding AllImage and left Binding there.
and then binding the source in your code behind.
ItemsSource="{Binding}"

and try ImageList.datacontext = ...
or other attr.
0
 

Author Comment

by:ctrlctrl
ID: 24433205
Hi rendaduiyan ,

sorry I didnt Understand what you meant , Please tell me in a little more detail.

Thank You
0
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 24438779
in XAML, tell listview ItemSource={Binding}. not assign the AllImage to it.
you AllImage is not visible in the XAML.

Instead, set the datacontext in the c#code for this XAML.
Or paste your XAML here.
0
 

Author Comment

by:ctrlctrl
ID: 24443194
a problem with this is , my listView is inside my datatemplate, I do not know how to access controls inside the datatemplate from code behind !! I also have a thread in this forum that asks how to access controls inside data template.

Please throw some light
0
 

Accepted Solution

by:
ctrlctrl earned 0 total points
ID: 24446002
Hi rendaduiyan:,

I solved it from this forum
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/db2458f8-5773-4363-8ef0-0fb9d14ecf72

Please try to answer my other thread , how to access controls in datatemplate from code behind !!!


Thank You
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question