Inserting images in runtime?

5 posts, 0 answers
  1. Vic
    Vic avatar
    3 posts
    Member since:
    Aug 2010

    Posted 02 Sep 2010 Link to this post

    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; 
       
                }
      
            }
      
        }
      
    }

  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 03 Sep 2010 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Vic
    Vic avatar
    3 posts
    Member since:
    Aug 2010

    Posted 03 Sep 2010 Link to this post

    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
  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 06 Sep 2010 Link to this post

    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
  6. Vic
    Vic avatar
    3 posts
    Member since:
    Aug 2010

    Posted 06 Sep 2010 Link to this post

    Thanks!!!!!
Back to Top
UI for WPF is Visual Studio 2017 Ready