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

Item template include image, problem if no items set

2 Answers 136 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Pinho
Top achievements
Rank 1
Pinho asked on 17 Mar 2009, 02:07 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Kaloyan
Telerik team
answered on 18 Mar 2009, 07:21 AM
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.
0
Pinho
Top achievements
Rank 1
answered on 18 Mar 2009, 11:02 AM
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
Tags
ComboBox
Asked by
Pinho
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Pinho
Top achievements
Rank 1
Share this question
or