When displaying "Name" from button collection, selected item is not displayed.
It looks pretty straight forward but I can't think of why it won't work.. hmm..
Is this a telerik bug?
The following code shows two different methods, "DataTemplate" and "DisplayMemberPath"
I appreciate for your help.
-chris
It looks pretty straight forward but I can't think of why it won't work.. hmm..
Is this a telerik bug?
The following code shows two different methods, "DataTemplate" and "DisplayMemberPath"
I appreciate for your help.
-chris
<
Window
x:Class
=
"RadComboBoxExample.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
>
<
Grid
x:Name
=
"grid"
>
<
Grid.Resources
>
<
DataTemplate
x:Key
=
"comboTemplate"
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
DataTemplate
>
</
Grid.Resources
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
StackPanel
Grid.Column
=
"0"
Orientation
=
"Vertical"
>
<
TextBlock
Text
=
"Use ItemTemplate"
Margin
=
"10"
FontSize
=
"15"
HorizontalAlignment
=
"Center"
/>
<
telerik:RadComboBox
x:Name
=
"comboBox1"
Width
=
"100"
Height
=
"30"
ItemsSource
=
"{Binding ButtonCollection1}"
SelectedItem
=
"{Binding SelectedButton1}"
ItemTemplate
=
"{StaticResource comboTemplate}"
/>
</
StackPanel
>
<
StackPanel
Grid.Column
=
"1"
Orientation
=
"Vertical"
>
<
TextBlock
Text
=
"Use DisplayMemberPath"
Margin
=
"10"
FontSize
=
"15"
HorizontalAlignment
=
"Center"
/>
<
telerik:RadComboBox
x:Name
=
"comboBox2"
Width
=
"100"
Height
=
"30"
Grid.Column
=
"1"
ItemsSource
=
"{Binding ButtonCollection2}"
SelectedItem
=
"{Binding SelectedButton2}"
DisplayMemberPath
=
"Name"
/>
</
StackPanel
>
</
Grid
>
</
Window
>
using
System.Collections.ObjectModel;
using
System.Windows;
using
Telerik.Windows.Controls;
namespace
RadComboBoxExample
{
public
partial
class
MainWindow : Window
{
public
ObservableCollection<RadButton> ButtonCollection1 {
get
;
set
; }
public
ObservableCollection<RadButton> ButtonCollection2 {
get
;
set
; }
public
RadButton SelectedButton1 {
get
;
set
; }
public
RadButton SelectedButton2 {
get
;
set
; }
public
MainWindow()
{
InitializeComponent();
ButtonCollection1 =
new
ObservableCollection<RadButton>();
ButtonCollection2 =
new
ObservableCollection<RadButton>();
for
(
int
i = 0; i < 10; i++)
{
RadButton button1 =
new
RadButton();
button1.Name =
"Button1_Item"
+ i;
ButtonCollection1.Add(button1);
RadButton button2 =
new
RadButton();
button2.Name =
"Button2_Item"
+ i;
ButtonCollection2.Add(button2);
}
grid.DataContext =
this
;
}
}
}