I have a RadRibbonComboBox in a RadRibbonTab in a RadRibbonBar. Looks something like this:
I have defined three different Data Templates in the resources like this:
I want to use a specific Data Template for the EmptySelectionBoxTemplate depending on various conditions. Therefore, I want to set the EmptySelectionBoxTemplate in code. I have tried setting the template like this:
The resource is found, and appears to be set in the combo box, but the display does not get altered. I also tried invalidating the property and visual state:
Invalidating did not help. The combo box selection is -1, and if I set the EmptySelectionBoxTemplate in XAML, the box displays the message correctly.
What is the correct way to change this template in code?
<
telerik:RadRibbonBar
>
<
telerik:RadRibbonTab
Header
=
"Tab 2"
x:Name
=
"Tab2"
>
<
telerik:RadRibbonGroup
Header
=
"Select an item"
>
<
StackPanel
Orientation
=
"Vertical"
Margin
=
"0,5,0,0"
>
<
telerik:RadRibbonComboBox
Name
=
"myComboBox"
Margin
=
"0,5,0,0"
>
<
telerik:RadRibbonComboBoxItem
Content
=
"New Item..."
Selected
=
"NewItem_Selected"
></
telerik:RadRibbonComboBoxItem
>
</
telerik:RadRibbonComboBox
>
</
StackPanel
>
</
telerik:RadRibbonGroup
>
</
telerik:RadRibbonTab
>
</
telerik:RadRibbonBar
>
I have defined three different Data Templates in the resources like this:
<
UserControl.Resources
>
<
DataTemplate
x:Key
=
"EmptyTemplate1"
>
<
TextBlock
FontStyle
=
"Italic"
Text
=
"Select a value from the list"
/>
</
DataTemplate
>
<
DataTemplate
x:Key
=
"EmptyTemplate2"
>
<
TextBlock
FontStyle
=
"Italic"
Text
=
"There are no selections at this time"
/>
</
DataTemplate
>
<
DataTemplate
x:Key
=
"EmptyTemplate3"
>
<
TextBlock
FontStyle
=
"Italic"
Text
=
"Please complete the first tab before selecting"
/>
</
DataTemplate
>
</
UserControl.Resources
>
I want to use a specific Data Template for the EmptySelectionBoxTemplate depending on various conditions. Therefore, I want to set the EmptySelectionBoxTemplate in code. I have tried setting the template like this:
myComboBox.EmptySelectionBoxTemplate = (DataTemplate)FindResource(
"EmptyTemplate1"
);
The resource is found, and appears to be set in the combo box, but the display does not get altered. I also tried invalidating the property and visual state:
myComboBox.InvalidateProperty(RadComboBox.EmptySelectionBoxTemplateProperty);
myComboBox.InvalidateVisual();
Invalidating did not help. The combo box selection is -1, and if I set the EmptySelectionBoxTemplate in XAML, the box displays the message correctly.
What is the correct way to change this template in code?