Binding fails in RadTileView's ListBox

3 posts, 1 answers
  1. Nemo
    Nemo avatar
    12 posts
    Member since:
    Jul 2012

    Posted 15 Jun 2012 Link to this post

    I have a RadTileView(Bind to an Observablecollection in ViewModel) , TileView has a ListBox (binded to a Dictionary). I am not able to capture SelectedItem from the ListBox in the ViewModel. Could you please check what went wrong in this code?

            <DataTemplate x:Key="DictionaryTemplate">
                <StackPanel Orientation="Horizontal" >
                    <TextBlock  Text="{Binding Key}" FontSize="14" />
                    <TextBlock  Text=" - " FontSize="14" />
                    <TextBlock Text="{Binding Value}" FontSize="14"/>
    <!-- End of DictionaryTemplate-->
    <telerik:RadTileView Name="ResultTileView"       
                         ItemsSource="{Binding ResultCollection}"    
    Width="1160" Height="Auto"
    MaximizeMode="Zero" >
    <!--Item Template-->
                  <StackPanel Orientation="Horizontal" >
                        <TextBlock Text="{Binding Name}"/>                                                  
    <!—End of Item Template-->
    <!--Content Template-->
         <telerik:RadTileView.ContentTemplate  >
                     <ListBox Name="ResultLBox"
    ItemsSource="{Binding KeyDictionary }"
    ItemTemplate="{StaticResource DictionaryTemplate}" 
                         SelectedItem="{Binding SelectedKeyDictionary}"
    public class Result
     string name;
            public string Name
                get { return name; }
                set { name = value; }
            private Dictionary<string, string> keyDictionary;
            public Dictionary<string, string> KeyDictionary
                get { return keyDictionary; }
                set { keyDictionary = value; }
    public class HomeViewModel : INotifyPropertyChanged
    #region Constructor
          public HomeViewModel()
           //Bind to RadTileView
           ObservableCollection<Result> resultCollection;
           public ObservableCollection<Result> ResultCollection
                get { return resultCollection; }
                    resultCollection = value;
    //Bind to SelectedItem of RadListBox
    private Dictionary<string, string> selectedKeyDictionary;
    public Dictionary<string, string> SelectedKeyDictionary
                get { return selectedKeyDictionary; }
                set { selectedKeyDictionary = value;
    //Fill the ObservableCollection
    void AddData()
                Dictionary<string, string> resultDictionary1 = new Dictionary<string, string>();
                resultDictionary1.Add("Key1", "Value1");
                Dictionary<string, string> resultDictionary2 = new Dictionary<string, string>();
                resultDictionary2.Add("Key2", "Value2");
                Dictionary<string, string> resultDictionary3 = new Dictionary<string, string>();
                resultDictionary3.Add("Key3", "Value3");
                Dictionary<string, string> resultDictionary4 = new Dictionary<string, string>();
                resultDictionary4.Add("Key4", "Value4");
                Dictionary<string, string> resultDictionary5 = new Dictionary<string, string>();
                resultDictionary5.Add("Key5", "Value5");
                Result rel1 = new Result() { Name = "Result1", KeyDictionary = resultDictionary1 };
                Result rel2 = new Result() { Name = "Result2", KeyDictionary = resultDictionary2 };
                Result rel3 = new Result() { Name = "Result3", KeyDictionary = resultDictionary3 };
                Result rel4 = new Result() { Name = "Result4", KeyDictionary = resultDictionary4 };
                Result rel5 = new Result() { Name = "Result5", KeyDictionary = resultDictionary5 };
                ResultCollection = new ObservableCollection<Result>();
    #region INotifyPropertyChanged
           public event PropertyChangedEventHandler PropertyChanged;
           protected virtual void NotifyPropertyChanged(String info)
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(info));

  2. Answer
    Zarko avatar
    755 posts

    Posted 20 Jun 2012 Link to this post

    Hello Pratihbha,
    The problem is that the DataContext of your RadTileViewItems are Result but you try to bind the SelectedItem to a property that is in your HomeViewModel (SelectedKeyDictionary). You'll have to add a SelectedKey property to your Result business object and maybe handle the propertyChanged event in the HomeViewModel so that you could populate the SelectedKeyDictionary.
    I've attached a sample project so could you please examine it and if you have further questions feel free to ask.

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Nemo
    Nemo avatar
    12 posts
    Member since:
    Jul 2012

    Posted 21 Jun 2012 Link to this post

    Thank you Zarko!
Back to Top