This is a migrated thread and some comments may be shown as answers.

Inserting images in runtime?

4 Answers 106 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Vic
Top achievements
Rank 1
Vic asked on 03 Sep 2010, 12:08 AM
Hello I have a problem with RadCarousel, at runtime you can not add items to the carousel OpenDialog because when I connect my ItemSource with images not see it, I realized that if the images are not shown in project resources can not be seen ...
What I have to do to see the images that are not in the resources folder?

DataTemplate?

C # code?

thank you very much, sorry for my english

 

   
  
public partial class Window1 : Window 
    {
        List<Image> lista; 
        private const String Extension = "(*.jpg)|*.jpg|(*.png)|*.png"
  
        public Window1() 
        {
            InitializeComponent();
            lista = new List<Image>();
            Microsoft.Win32.OpenFileDialog dialog ;
         }
  
        private void button1_Click(object sender, RoutedEventArgs e) 
            {
  
                lista.Clear();
                dialog = new Microsoft.Win32.OpenFileDialog { RestoreDirectory = true, Filter = Extension, Multiselect = true }; 
            
       if (dialog.ShowDialog() == true
                    {
                         foreach (string Name in dialog.FileNames) 
                 {
                        Image Im = new Image()
                Im.Source = new BitmapImage(new Uri(fName, UriKind.Relative)); 
                         lista.Add(Im);
  
                }
  
            this.radCarousel1.ItemsSource = lista; 
   
            }
  
        }
  
    }
  
}

4 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 03 Sep 2010, 06:52 AM
Hello Vic,

You just have to use ObservableCollection in stead of List so that the carousel receives notifications when new items are added to your source collection. 


All the best,
Milan
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
0
Vic
Top achievements
Rank 1
answered on 03 Sep 2010, 04:27 PM
I understand but I have had problems, I captured the notification and will insert the list at the carousel ItemSource but does not display images ...





public
partial class Window1 : Window
    {
        private RadObservableCollection<Image> list;
        private const String ExtensionFilter = "(*.jpg)|*.jpg|(*.png)|*.png";
          
  
        public Window1()
        {
            InitializeComponent();
            list = new RadObservableCollection<Image>();
list.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(list_CollectionChanged);
        }
  
private void list_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                this.radCarousel1.ItemsSource = (Image)sender;
            }
        }
  
        private void button1_Click(object sender, RoutedEventArgs e)
        {
              
Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog { RestoreDirectory = true, Filter = ExtensionFilter, Multiselect = true };
  
            if (dialog.ShowDialog() == true)
            {
                foreach (string fileName in dialog.FileNames)
                {
                    Image Im = new Image();
             Im.Source = new BitmapImage(new Uri(fileName, UriKind.Relative));
                     
                    list.Add(Im);
                }
  
                   }
            else
            {
  
            }
  
  
        }
  
          
    }
}


thanks
0
Milan
Telerik team
answered on 06 Sep 2010, 03:19 PM
Hi Vic,

There is no need to handle CollectionChange and modify the ItemsSource of the carousel when a new item is added to the source collection. You just need to assign ItemsSource once and the control will take care of the rest.

public Window1() 
        
            InitializeComponent(); 
            list = new RadObservableCollection<Image>(); 
  
            this.radCarousel1.ItemsSource = list
  
            // no need to handle CollectionChanged
//list.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(list_CollectionChanged); 
        }


Best wishes,
Milan
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
0
Vic
Top achievements
Rank 1
answered on 06 Sep 2010, 11:39 PM
Thanks!!!!!
Tags
Carousel
Asked by
Vic
Top achievements
Rank 1
Answers by
Milan
Telerik team
Vic
Top achievements
Rank 1
Share this question
or