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

Change EmptyText to ClearSelectionButtonContent

1 Answer 99 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
yjh
Top achievements
Rank 1
yjh asked on 11 Jul 2011, 03:54 PM
Is there a way to change EmptyText to ClearSelectionButtonContent when click the ClearSelectionButton ?

1 Answer, 1 is accepted

Sort by
0
Accepted
Pana
Telerik team
answered on 13 Jul 2011, 08:15 AM
Hi,

You can. Create a Converter and bind the

ClearSelectionButtonContent

to the SelectedItem of the RadComboBox. In the converter based on the value you can return two different strings:

<UserControl.Resources>
    <local:SelectedItemToClearTextConverter x:Key="Convert" />
</UserControl.Resources>
  
<Grid x:Name="LayoutRoot" Background="White">
    <telerik:RadComboBox x:Name="Combo" Width="150" Height="22" SelectedIndex="0" ClearSelectionButtonVisibility="Visible" ClearSelectionButtonContent="{Binding ElementName=Combo, Path=SelectedItem, Converter={StaticResource Convert}}">
        <telerik:RadComboBoxItem Content="Item 1" />
        <telerik:RadComboBoxItem Content="Item 2" />
        <telerik:RadComboBoxItem Content="Item 3" />
        <telerik:RadComboBoxItem Content="Item 4" />
        <telerik:RadComboBoxItem Content="Item 5" />
        <telerik:RadComboBoxItem Content="Item 6" />
    </telerik:RadComboBox>
</Grid>

With converter:

public class SelectedItemToClearTextConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value == null)
        {
            return "Can not unselect null";
        }
        else
        {
            return "Unselect";
        }
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

There is also an attached project.

As I think of it with the same success you can bind the visibility of the button so it could be hidden when there is no selected item.

Regards,
Pana
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
ComboBox
Asked by
yjh
Top achievements
Rank 1
Answers by
Pana
Telerik team
Share this question
or