This question is locked. New answers and comments are not allowed.
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?
Home.xaml
<
UserControl.Resources
>
<!--DictionaryTemplate-->
<
DataTemplate
x:Key
=
"DictionaryTemplate"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
TextBlock
Text
=
"{Binding Key}"
FontSize
=
"14"
/>
<
TextBlock
Text
=
" - "
FontSize
=
"14"
/>
<
TextBlock
Text
=
"{Binding Value}"
FontSize
=
"14"
/>
</
StackPanel
>
</
DataTemplate
>
<!-- End of DictionaryTemplate-->
</
UserControl.Resources
>
<
StackPanel
>
<
telerik:RadTileView
Name
=
"ResultTileView"
ItemsSource
=
"{Binding ResultCollection}"
MaxColumns
=
"4"
ColumnWidth
=
"290"
RowHeight
=
"180"
HorizontalAlignment
=
"Center"
MinimizedColumnWidth
=
"350"
MinimizedRowHeight
=
"350"
Width
=
"1160"
Height
=
"Auto"
MaximizeMode
=
"Zero"
>
<!--Item Template-->
<
telerik:RadTileView.ItemTemplate
>
<
DataTemplate
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:RadTileView.ItemTemplate
>
<!—End of Item Template-->
<!--Content Template-->
<
telerik:RadTileView.ContentTemplate
>
<
DataTemplate
>
<
StackPanel
>
<
ListBox
Name
=
"ResultLBox"
ItemsSource
=
"{Binding KeyDictionary }"
ItemTemplate
=
"{StaticResource DictionaryTemplate}"
SelectedItem
=
"{Binding SelectedKeyDictionary}"
Height
=
"100"
Width
=
"200"
/>
</
ListBox
>
</
StackPanel
>
</
DataTemplate
>
</
telerik:RadTileView.ContentTemplate
>
</
telerik:RadTileView
>
</
StackPanel
>
Model:
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; }
}
}
ViewModel:
public class HomeViewModel : INotifyPropertyChanged
{
#region Constructor
public HomeViewModel()
{
AddData();
}
#endregion
//Bind to RadTileView
ObservableCollection<
Result
> resultCollection;
public ObservableCollection<
Result
> ResultCollection
{
get { return resultCollection; }
set
{
resultCollection = value;
NotifyPropertyChanged("ResultCollection");
}
}
//Bind to SelectedItem of RadListBox
private Dictionary<
string
, string> selectedKeyDictionary;
public Dictionary<
string
, string> SelectedKeyDictionary
{
get { return selectedKeyDictionary; }
set { selectedKeyDictionary = value;
NotifyPropertyChanged("SelectedKeyDictionary");
}
}
//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
>();
ResultCollection.Add(rel1);
ResultCollection.Add(rel2);
ResultCollection.Add(rel3);
ResultCollection.Add(rel4);
ResultCollection.Add(rel5);
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
#endregion
}