Item template include image, problem if no items set

3 posts, 1 answers
  1. Pinho
    Pinho avatar
    42 posts
    Member since:
    Mar 2009

    Posted 17 Mar 2009 Link to this post

    Hi,

     I'm using a telerik combo box to show the possible cultures. To get this effect I'm using an image with the culture flag and a text box with the culture code (US, EN, FR, PT, etc)

     The list of available cultures depends on the several things, so, I load this either at startup or by request.

     The problem is when the collection is empty or I reset it (clear all items).

     If this occurs, the error appears on the left bottom corner of the browser with the error " ag_e_network_error #4001" - from what I could see it has something to do with images.

     Item object code:

    /// <summary> 
        /// Class used to match the items used to identify the culture information 
        /// </summary> 
        public class CultureInfoItem : INotifyPropertyChanged, IEquatable<CultureInfoItem> 
        { 
            private string cultureInfoID; 
     
            public string CultureInfoID 
            { 
                get { return cultureInfoID; } 
                set 
                { 
                    cultureInfoID = value
                    if (PropertyChanged != null) 
                        PropertyChanged(this, new PropertyChangedEventArgs("CultureInfoID")); 
                } 
            } 
            private string cultureInfoFlag; 
     
            public string CultureInfoFlag 
            { 
                get { return cultureInfoFlag; } 
                set 
                { 
                    cultureInfoFlag = value
                    if (PropertyChanged != null) 
                        PropertyChanged(this, new PropertyChangedEventArgs("CultureInfoFlag")); 
                } 
            } 
     
            public CultureInfoItem(string cultureID) 
            { 
                CultureInfoID = cultureID
                CultureInfoFlag = string.Format("/Ngp.Presentation.Framework.GUI;component/Images/Flags/{0}.png", cultureID!=string.Empty?cultureID:"emptyFlag"); 
            } 
     
            #region INotifyPropertyChanged Members 
     
            public event PropertyChangedEventHandler PropertyChanged; 
     
            #endregion 
     
            #region IEquatable<CultureInfoItem> Members 
     
            public bool Equals(CultureInfoItem other) 
            { 
                return (this.CultureInfoID == other.CultureInfoID); 
            } 
     
            #endregion 
        } 

    XAML combo box definition:

            <telerikInput:RadComboBox x:Name="cmbCultureSelector" Width="42" Height="22" MinHeight="0" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Visible" Opacity="0.80" Margin="2,2,2,2" Grid.Row="1" Grid.Column="3" SelectionChanged="cmbCultureSelection_SelectionChanged"
                <telerikInput:RadComboBox.ItemTemplate> 
                    <DataTemplate> 
                        <StackPanel Orientation="Horizontal"
                            <Image Source="{Binding Path=CultureInfoFlag}" Height="11" Margin="2,2,2,2"/> 
                            <TextBlock Text="{Binding Path=CultureInfoID}" FontFamily="Verdana" FontSize="9" VerticalAlignment="Center" /> 
                        </StackPanel> 
                    </DataTemplate> 
                </telerikInput:RadComboBox.ItemTemplate> 
                <telerikInput:RadComboBox.SelectionBoxItemTemplate> 
                    <DataTemplate> 
                        <Image Source="{Binding Path=CultureInfoFlag}" Height="11" Margin="2,0,2,2" VerticalAlignment="Center"/> 
                    </DataTemplate> 
                </telerikInput:RadComboBox.SelectionBoxItemTemplate> 
            </telerikInput:RadComboBox> 

    Object "binded" to the combo box:

    internal ObservableCollection<CultureInfoItem> cultureInfoCollection; 






    Could you please help me?

    Thanks,

    L. Pinho


  2. Answer
    Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 18 Mar 2009 Link to this post

    Hi Luis,

    The problem is that you have defined a template which consist of an image and this template is used as SelectionBoxItemTemplate. That means that you always have to provide a valid image even if the collection is empty, because then the source of the image will be null and that's why you get this "ImageError"(Image is trying to get source which is null). To avoid this error you can clear the ItemTemplate and SelectionBoxItemTemplate before you clear the collection, or set valid ComboBox SelectedIndex. Attached you can find a possible solution of this issue.

    Let us know if you need more help.

    Best wishes,
    Kaloyan Manev
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Pinho
    Pinho avatar
    42 posts
    Member since:
    Mar 2009

    Posted 18 Mar 2009 Link to this post

    Hi Kaloyan,

     thank you soo much for this, it worked correctly.

     Thanks also for the example, it was great that you could use my own example to make a new one, it reduced my development time, and reduced the understanding curve :)

     Again, 5 star support !!!

    Thanks,

    L. Pinho
Back to Top