This is a migrated thread and some comments may be shown as answers.

Style Radcombobox watermark/emptytext

3 Answers 806 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mads
Top achievements
Rank 1
Mads asked on 15 Sep 2015, 11:14 AM

I want to add a style to the emptytext of the radcombobox that works across the entire application. 

 From what I can see I have to use http://docs.telerik.com/devtools/wpf/controls/radcombobox/howto/create-a-watermark but if I use 

<DataTemplate x:Key="EmptyTemplate">
 <TextBlock FontWeight="Bold" FontFamily="Comic Sans" FontStyle="Italic" Text="Please select an agency" />
</DataTemplate>
 Then I cant specify the text in the control that uses it like

<telerik:RadComboBox Grid.Column="3"
                                 Grid.Row="3"
                                 SelectedItem="{Binding Path=CreateVetPcrTestSignup.SelectedVetPcrTestKit}"
                                 DisplayMemberPath="Name"
                                 IsEditable="False"
                                 EmptySelectionBoxTemplate="{StaticResource EmptyTemplate}"
                                  
                                 EmptyText="{x:Static localization:SignupTexts.PcrKitDefaultValue}"
                                 ItemsSource="{Binding Path=PcrTestKits}" />

 

I want {x:Static localization:SignupTexts.PcrKitDefaultValue} to be used here, but I of course get "Please select an agency", I tried removing the name from the template, but then its just empty. Is there a way to parse the empty text into the template or use a styling somehow that only affects the emptytext?

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 18 Sep 2015, 06:12 AM
Hello Mads,

In order to apply the desired Template for the EmptyText and at the same time preserve its value the Text property of the TextBlock placed inside the DataTemplate should be bound to the EmptyText property of RadComboBox.

We have created a sample project that demonstrates that and you could run and evaluate it.

Hopes this helps.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Anish
Top achievements
Rank 1
answered on 31 Jul 2018, 06:54 AM
Hi.. Is there any way I can implement this with IsEditable="True". If not how do I achieve this?
0
Dinko | Tech Support Engineer
Telerik team
answered on 31 Jul 2018, 01:01 PM
Hello Anish,

The EmptySelectionBoxTemplate is applied only for non-editable ComboBox. The watermark of RadComboBox is presented with a TextBlock with x:Name="Watermark", so In the described case you could find the TextBlock and set its properties with code. You can subscribe to the Loaded event handler of the RadComboBox and use our ChildrenOfType<T>() extension method you can get the TextBlock. Check the following code snippet.
private void combo_Loaded(object sender, RoutedEventArgs e)
{
    var comboBox = sender as RadComboBox;
    TextBlock watermarkTextBlock = comboBox.ChildrenOfType<TextBlock>().FirstOrDefault(x=>x.Name == "Watermark");
    if (watermarkTextBlock != null)
    {
        watermarkTextBlock.FontWeight = FontWeights.Bold;
        watermarkTextBlock.FontFamily = new FontFamily("Comic Sans");
        watermarkTextBlock.Opacity = 1;
        watermarkTextBlock.FontStyle = FontStyles.Italic;
    }
}

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ComboBox
Asked by
Mads
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Anish
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or