I am using a Telerik theme (VisualStudio2013) and want to change the color of certain controls within my ListBox depending on the selection state. So in my contrived example below I want the BorderBrush and Separator Background to become blue (the VisualStudio2013 color) when the associated ListBoxItem is selected.
My attempt shown below with a RelativeSource binding does not work.
<
Window
x:Class
=
"TelerikWpfApp2.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
DataContext
=
'{Binding RelativeSource={RelativeSource Self}}'
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
>
<
Window.Resources
>
<
DataTemplate
x:Key
=
"MyItemTemplate"
>
<
StackPanel
>
<
Label
Content
=
"{Binding}"
/>
<
Border
Height
=
"30"
Background
=
"White"
BorderBrush
=
"{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadListBoxItem}}}"
Padding
=
"2"
BorderThickness
=
"5"
>
<
Separator
Background
=
"{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadListBoxItem}}}"
Height
=
"4"
Margin
=
"6"
></
Separator
>
</
Border
>
</
StackPanel
>
</
DataTemplate
>
</
Window.Resources
>
<
Grid
>
<
telerik:RadListBox
ItemTemplate
=
"{StaticResource MyItemTemplate}"
ItemsSource
=
"{Binding TheList}"
>
</
telerik:RadListBox
>
</
Grid
>
</
Window
>
public
partial
class
MainWindow : Window
{
public
ObservableCollection<
string
> TheList {
get
;
set
; } =
new
ObservableCollection<
string
> () {
"A"
,
"B"
,
"C"
};
public
MainWindow ()
{
InitializeComponent();
}
}